In r make a simulation to verify the following theorem: if X1 ∼ χ2n1 , X2 ∼ χ 2n2 , and X1 and X2 are independent, then X1 + X2 ∼ χ 2n1+n2 .
Please provide appropriate code for this problem.
You can use the code below:
CODE:
check = function(n1,n2,df1,df2){
x1 = rchisq(n1,2*df1)
x2 = rchisq(n2,2*df2)
y = x1+x2
library(e1071)
probplot(y,"qchisq",df = 2*(df1+df2))
}
check(2000,2000,10,20)
The above code will create the probability plot to visualize whether x1+x2 follows the required distribution.
You can see the plots for X1+X2 are falls on the straight lines in the graph, which indicates that they follow the chi-square distribution with df 2(n1 + n2).
Get Answers For Free
Most questions answered within 1 hours.