In: Statistics and Probability
Here is the R code for running a t-test:
t.test( numeric vector of data values, another optional numeric vector of data values,
alternative = c("two.sided", "less", "greater"),
mu = Ho, paired = c(TRUE, FALSE), var.equal = c(TRUE,FALSE),conf.level =1-)
1.) Suppose 30 students are all taking the same Math 115 and English 101 classes at CSUN. You want to know in which class students tend to do better. The data below represents the class averages of the students in both classes. Write the R code that does the following:
a.) Makes two boxplots one green for the Eng_101 and a blue one for Math_115 labels the main title as "Class averages for students taking Stats vs English” and names the Eng_101 data as “English 101” and the Math_115 data as “Intro to Statistics”.
b.) Computes the sample size, mean and standard deviation of the Eng_101 and Math_115.
c.) Performs a paired two-sided t-test with =.01 to Eng_101 and Math_115 to decide whether there has been a statistically significant difference between the class averages in English 101 and Math 115.
d.) Paste your R code into Run R Script and run the script.
e.) Paste the R output to the bottom R code.
f.) Looking at the p-value in the R output, decide if there is evidence to suggest that there is a statistically significant difference between the class averages in English 101 and Math 115. Write the p-value and your conclusion at the top of your R code.
Eng_101<-c( 80, 72, 73, 76, 79, 79, 79, 75, 75, 68, 70, 76, 79, 74, 73, 81,72, 74, 77, 83, 79,78, 72, 79,60,54,50,40,65,59)
Math_115<-c( 74, 67, 74, 70, 76, 60,56,45,66,81, 67, 63, 71, 76, 66, 73, 77, 68, 71, 75,
68, 79, 73, 85, 78, 77, 72, 77, 59,65)
Conclusion: Here p-value= 0.5835 which greater than 5% level of significance, therefore we may fail to reject null hypothesis and conclude that there is insufficient evidence that there is significant difference between the class averages in English 101 and Math 115. ie., there is no significant difference between the class averages in English 101 and Math 115.
The respective r-codes are given below, you can also customize that that r-codes .
> Eng_101<-c( 80, 72, 73, 76, 79, 79, 79, 75, 75, 68, 70,
76, 79, 74, 73, 81,72, 74, 77, 83, 79,78, 72,
79,60,54,50,40,65,59)
> Math_115<-c( 74, 67, 74, 70, 76, 60,56,45,66,81, 67, 63,
71, 76, 66, 73, 77, 68, 71, 75,68,79,73,85,78,77,72,77,59,65)
>
boxplot(dataframe,horizontal=FALSE,las=1,notch=FALSE,outline=TRUE,outcol="#512DA8",outpch=19,
col=c("Green","Blue"),xlab="",ylab="", main="Class averages for
students taking Stats vs English
",sub="",col.lab="#000000",col.main="#000000",col.sub="#000000",col.axis="#000000",cex.lab=1,cex.main=1,cex.sub=1,cex.axis=1)
> n1=length(Eng_101)
> n1
[1] 30
> n2=length(Math_115)
> n2
[1] 30
> m1=mean(Eng_101)
> m1
[1] 71.7
> m2=mean(Math_115)
> m2
[1] 70.3
> Sd1=sqrt(var(Eng_101))
> Sd1
[1] 9.986715
> Sd2=sqrt(var(Math_115))
> Sd2
[1] 8.225905
> Ttest=t.test(Eng_101,Math_115,paired=T,conf.level=0.95)
> Ttest
Paired t-test
data: Eng_101 and Math_115
t = 0.55454, df = 29, p-value = 0.5835
alternative hypothesis: true difference in means is not equal to
0
95 percent confidence interval:
-3.763463 6.563463
sample estimates:
mean of the differences
1.4