4 Changed "odd" to "even" in one place where I messed up. edited Jun 27 at 6:21 JimB 20.9k11 gold badge3030 silver badges7171 bronze badges To obtain the distribution for general $$n$$ when $$n$$ is oddeven we have to use some other than TransformedDistribution. We need to integrate the joint density function and treat $$0, $$x=1/2$$, and $$1/2 separately. To obtain the distribution for general $$n$$ when $$n$$ is odd we have to use some other than TransformedDistribution. We need to integrate the joint density function and treat $$0, $$x=1/2$$, and $$1/2 separately. To obtain the distribution for general $$n$$ when $$n$$ is even we have to use some other than TransformedDistribution. We need to integrate the joint density function and treat $$0, $$x=1/2$$, and $$1/2 separately. 3 Added in general formula for n. edited Jun 27 at 6:02 JimB 20.9k11 gold badge3030 silver badges7171 bronze badges fltOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 2 x - x1, {x1, 0, x}, Assumptions -> n > 1 && 0 < x < 1/2] (* -((4 ((1 - 2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x)* Gamma[n/2]^2)) *) fOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 1 - x1, {x1, 0, 1/2}, Assumptions -> n > 1] (* (2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2) *) (* Because the density is symmetric, we'll take advantage of that *) fgtOneHalf = FullSimplify[fltOneHalf /. x -> y /. y -> 1 - x] (* I(4 broke(-1 something.+ (3 Updating- shortly.2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, (-1 + x)/(-1 + 2 x)])/((-1 + 2 x) Gamma[n/2]^2) *) pdf[n_, x_] := Piecewise[{{-((4 ((1 - 2 x) x)^(n/2)*Gamma[n] Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x) Gamma[n/2]^2)), 0 < x < 1/2}, {(2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2), x == 1/2}, {(4 (-1 + (3 - 2 x) x)^(n/2) * Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, (-1 + x)/(-1 + 2 x)])/((-1 + 2 x) Gamma[n/2]^2), 1/2 < x < 1}}, 0]  fltOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 2 x - x1, {x1, 0, x}, Assumptions -> n > 1 && 0 < x < 1/2] (* -((4 ((1 - 2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x)* Gamma[n/2]^2)) *) fOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 1 - x1, {x1, 0, 1/2}, Assumptions -> n > 1] (* (2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2) *) fgtOneHalf = (* I broke something. Updating shortly. *)  fltOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 2 x - x1, {x1, 0, x}, Assumptions -> n > 1 && 0 < x < 1/2] (* -((4 ((1 - 2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x)* Gamma[n/2]^2)) *) fOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 1 - x1, {x1, 0, 1/2}, Assumptions -> n > 1] (* (2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2) *) (* Because the density is symmetric, we'll take advantage of that *) fgtOneHalf = FullSimplify[fltOneHalf /. x -> y /. y -> 1 - x] (* (4 (-1 + (3 - 2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, (-1 + x)/(-1 + 2 x)])/((-1 + 2 x) Gamma[n/2]^2) *) pdf[n_, x_] := Piecewise[{{-((4 ((1 - 2 x) x)^(n/2)*Gamma[n] Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x) Gamma[n/2]^2)), 0 < x < 1/2}, {(2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2), x == 1/2}, {(4 (-1 + (3 - 2 x) x)^(n/2) * Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, (-1 + x)/(-1 + 2 x)])/((-1 + 2 x) Gamma[n/2]^2), 1/2 < x < 1}}, 0]  2 Added most of the general case. edited Jun 27 at 4:55 JimB 20.9k11 gold badge3030 silver badges7171 bronze badges Mathematica does make this pretty easy. The statistic of interest is the typical estimator of the median when the sample size is even. When the sample size is odd the sample median has a beta distribution: OrderDistribution[{UniformDistribution[{0, 1}], n}, (n + 1)/2] (* BetaDistribution[(1 + n)/2, 1 + 1/2 (-1 - n) + n] *)  FirstNow for the case when $$n$$ is even. First find the joint distribution of the middle two order statistics. Then find the distribution of the mean of those two statistics. n = 6; od = OrderDistribution[{UniformDistribution[{0, 1}], n}, {n/2, n/2 + 1}]; md = TransformedDistribution[(x1 + x2)/2, {x1, x2} \[Distributed] od]; PDF[md, x] Plot[Evaluate[PDF[md, x]], {x, 0, 1}] All ofTo obtain the distributions will be symmetric so I'm sure that there's some closed-formdistribution for the density of general sample size (both$$n$$ when $$n$$ is odd and even sample sizes) that someone has already done inwe have to use some other than TransformedDistribution. We need to integrate the 19th or 20th centuryjoint density function and treat (or maybe even earlier)$$0, $$x=1/2$$, and $$1/2 separately. fltOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 2 x - x1, {x1, 0, x}, Assumptions -> n > 1 && 0 < x < 1/2] (* -((4 ((1 - 2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x)* Gamma[n/2]^2)) *) fOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 1 - x1, {x1, 0, 1/2}, Assumptions -> n > 1] (* (2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2) *) fgtOneHalf = (* I broke something. Updating shortly. *)  Putting this together in a single function: Mathematica does make this pretty easy. First find the joint distribution of the middle two order statistics. Then find the distribution of the mean of those two statistics. n = 6; od = OrderDistribution[{UniformDistribution[{0, 1}], n}, {n/2, n/2 + 1}]; md = TransformedDistribution[(x1 + x2)/2, {x1, x2} \[Distributed] od]; PDF[md, x] Plot[Evaluate[PDF[md, x]], {x, 0, 1}] All of the distributions will be symmetric so I'm sure that there's some closed-form for the density of general sample size (both odd and even sample sizes) that someone has already done in the 19th or 20th century (or maybe even earlier). Mathematica does make this pretty easy. The statistic of interest is the typical estimator of the median when the sample size is even. When the sample size is odd the sample median has a beta distribution: OrderDistribution[{UniformDistribution[{0, 1}], n}, (n + 1)/2] (* BetaDistribution[(1 + n)/2, 1 + 1/2 (-1 - n) + n] *)  Now for the case when $$n$$ is even. First find the joint distribution of the middle two order statistics. Then find the distribution of the mean of those two statistics. n = 6; od = OrderDistribution[{UniformDistribution[{0, 1}], n}, {n/2, n/2 + 1}]; md = TransformedDistribution[(x1 + x2)/2, {x1, x2} \[Distributed] od]; PDF[md, x] Plot[Evaluate[PDF[md, x]], {x, 0, 1}] To obtain the distribution for general $$n$$ when $$n$$ is odd we have to use some other than TransformedDistribution. We need to integrate the joint density function and treat $$0, $$x=1/2$$, and $$1/2 separately. fltOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 2 x - x1, {x1, 0, x}, Assumptions -> n > 1 && 0 < x < 1/2] (* -((4 ((1 - 2 x) x)^(n/2) Gamma[n]* Hypergeometric2F1[1 - n/2, n/2, (2 + n)/2, x/(-1 + 2 x)])/((-1 + 2 x)* Gamma[n/2]^2)) *) fOneHalf = 2 Integrate[(x1^(-1 + n/2) (1 - x2)^(-1 + n/2) n!)/((-1 + n/2)!)^2 /. x2 -> 1 - x1, {x1, 0, 1/2}, Assumptions -> n > 1] (* (2^(2 - n) n!)/((-1 + n) ((-1 + n/2)!)^2) *) fgtOneHalf = (* I broke something. Updating shortly. *)  Putting this together in a single function: 1 answered Jun 26 at 22:03 JimB 20.9k11 gold badge3030 silver badges7171 bronze badges