# Probability density in 3D shape

If Z = (X1,X2,X3) is a random point in rectangular coords chosen from the uniform distribution on the interior of a unit 3d ball, how do i find the probability density of a distance like R = root(X1^2+X2^2+X3^2), and also how do i find the probability density of a single coordinate like X1

Im assuming I need to find the probabilities in spherical cords and then make a conversion? (like r chosen from 0 to 1 and then theta chosen from 0 to 2pi, and phi chosen from 0 to pi as well). I'm not sure how to do this though...

Given the sphere of center 0 and radius 1.

The probability density given $$r$$ must be proportional to the area of a sphere of radius $$r$$. The area is $$4πr^2$$. The definite integral of this equation from 0 to 1 is $$4π/3$$ so the PDF given $$r$$ is $$p(r)=3r^2$$, this is, the formula divided by its definite integral.

The probability density of $$x$$ is proportional to the area of the circle inside the sphere, this circle is orthogonal to dimension X at each value $$x$$. The area of this circle given $$x$$ is $$π(1-x^2)$$. The definite integral of this equation from -1 to 1 is $$4π/3$$ so the PDF for $$x$$ is $$p(x)=3(1-x^2)/4$$. Again, this result is the formula divided by its definite integral.

Comment (too long for comment format): Your outline toward an analytic solution seems feasible. I haven't tried it, but it might be easier to stay with rectangular coordinates, initially integrating over a uniform distribution on the ball.

Below are some simulated distributions, means, and standard deviations.

x1 is one coordinate; R is squared distance from origin; r is distance from origin.

set.seed(2020)
m = 10^6
u1 = runif(m,-1,1); u2 = runif(m,-1,1); u3 = runif(m,-1,1)
ball = (u1^2 + u2^2 + u3^2 <= 1)
sum(ball)
[1] 523552     # points inside ball
(4/3)*pi/8
[1] 0.5235988  # volume of ball

# eliminate points outside ball
x1 = u1[ball]; x2 = u2[ball];  x3 = u3[ball]
mean(x1); sd(x1)
[1] -0.0001425727   # aprx E(X1) = 0
[1] 0.4469488
par(mfrow=c(2,2))
hist(x1, prob=T, col="skyblue2")
# for clarity: reduced nr of pts in scatterplot
plot(x1[1:10000],x2[1:10000], pch=".")

R = x1^2 + x2^2 + x3^2
mean(R);  sd(R)
[1] 0.6002077
[1] 0.2619311
hist(R, prob=T, col="skyblue2")

r = sqrt(R)
mean(r); sd(r)
[1] 0.7501263
[1] 0.1936963
hist(r, prob=T, col="skyblue2")
par(mfrow=c(1,1))