how to check a propriety using r studio

133 Views Asked by At

I have to check that this propriety

$Z \sim N(0,1)$ and $U\sim \chi ^{2}(10)$ then $ Z/\sqrt{U/10} \sim T(10)$

is true using r studio if anyone can help , much appreciate

3

There are 3 best solutions below

0
On

You could compare the moments of your distribution with the theoretical moments of $T(10)$

0
On

One approach could be simulation of thousands of values:

  • Simulate $Z$ using rnorm
  • Simulate $U$ using rchisq
  • Do the division $Y = Z / \sqrt{U / 10}$
  • Simulate the same number of $T$ from the hypothesised $t$-distribution using rt
  • Sort $Y$ and $T$ and plot them against each other - you want to see a diagonal straight line essentially $y=x$ with a little noise; this is visual demonstration though not a proof that the distributions are the same

You can do similar things with the qqplot function if you know what you are doing

0
On

I agree with @angryavian that you can't do a 'proof' in R. Also, it is crucial to state that random variables $Z$ and $U$ are independent. Then $Y = \frac{Z}{U/\sqrt{10}} \sim \mathsf{T}(10)$ by definition.

Here is R code to simulate a million values of $T$ [as in the Answer of @Henry (+1)], then to compare their histogram with the density of $\mathsf{T}(10).$ This is a graphical demonstration that $T$ has (at least very nearly) the claimed t distribution.

set.seed(405)  # for reproducibility
z = rnorm(10^6);  u = rchisq(10^6, 10)
y = z/sqrt(u/10)
hist(y, prob=T, br=50, col="skyblue2")
curve(dt(x, 10), add=T, lwd=2)

enter image description here

Furthermore, you could check that the quantiles of $Y$ very nearly match the theoretical quantiles of $\mathsf{T}(10).$

summary(y)
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
-10.641101  -0.699409   0.000059   0.000221   0.701253   9.802922 
qt(c(.25,.5,.75), 10)
[1] -0.6998121  0.0000000  0.6998121

The summary above also shows that $\bar Y \approx 0.$ And the sample variance of the simulated values of $Y$ is very nearly the variance $\nu/(\nu - 2) = 10/8 = 1.25$ of Student's t distribution with $\nu = 10$ degrees of freedom. [In effect, two of the moments suggested by #GeorgeDewhirts (+1).]

var(y);  10/8
[1] 1.250115
[1] 1.25

Also, you could do a Kolmogorov-Smirnov goodness-of-fit test on the first 5000 values of $Y$ and check that the P-value exceeds 5%. (The K-S test in R is limited to 5000 observations.) Roughly speaking, this is a formal, quantitative way to do @Henry's comparison of sorted observations.

ks.test(y[1:5000], pt, 10)

    One-sample Kolmogorov-Smirnov test

data:  y[1:5000]
D = 0.013661, p-value = 0.3083
alternative hypothesis: two-sided