Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use Rstudio. thank you! Explore Lsxsagls. Test: Generate two samples: Sam

ID: 3170328 • Letter: P

Question

Please use Rstudio. thank you!

Explore Lsxsagls. Test: Generate two samples: Sample A: m = 10 observations from a Normal(mu = 0, standarddeviation^2 = 1) distribution. Sample B: n = 20 observations from a Normal(mu = 0, standarddeviation^2 = 4) distribution. Combine the two samples into one vector, and create another vector that indicates which group the observations belong to. Perform Levene's test in R using the 'Levene test()' function in the library 'car', as you learned in lab on Friday 2/13. Report the resulting p-value, and summarize your findings (state the hypothesis tested, the results of your analysis, and your conclusions). Repeat the above process 5,000 times using a for loop, and store the resulting p-values. How many of the p-values are less than 0.05 (and would therefore lead you to reject the hypothesis that the variances are equal at level alpha = 0.05)? Discuss your findings: would Levene's test reliably inform you that the population variances are different?

Explanation / Answer

1>a>to answer this question use the following r codes

x=rnorm(10,0,1) #generating random sample

x
y=rnorm(20,0,4)
y
z=c(x,y) #combining two samples
z
group <- as.factor(c(rep(1, length(x)), rep(2, length(y)))) #creating a vector of size 30
group

1<b> run the following r codes
#install.packages("car")
library(car)
w=leveneTest(z,group) #performing levene test
w
pvalue=w$"Pr(>F)"[1:1]

pvalue # 0.02994471

#our null hypothesis is H0:sigma1=sigma2

sigma1=variance of 1st population

sigma2=variance of 2nd population

here you can find that the p value is  0.02994471 which is less than 0.05 so we will reject the null hypothisis

#

<c>#use the following r codes
pvalueLevene<-numeric(5000)   
for(i in 1:5000)
{
sim_x<-rnorm(10,0,1)
sim_y<-rnorm(20,0,4)
xy<-c(sim_x,sim_y)
alldata<-data.frame(xy,group)

pvalueLevene[i]<-leveneTest(alldata$xy ~ alldata$group, data = alldata)$"Pr(>F)"[1:1]

}

observedlevene<-sum(pvalueLevene < 0.05)
observedlevene #4730

#you can find out that 4730 out of 5000 p values lies below .05 so we can easily conclude that the population variances are diffrent.