In: Statistics and Probability
# 2: T test for two means
The data in SteelStrengthData.txt consists ofn1= 32 strength measurements of cold-rolled steel andn2= 35 measurements of two-sided galvanized steel. Import it into the data framedf2 and complete the following parts.
Use boxplot(Value∼Sample, notch=TRUE, data=df2) to do a comparative box plot. Do the two medians appear significantly different? (NOTE:∼does not copy-paste well.)
Test the hypothesisH0:μ1−μ2= 0 vs Ha:μ1−μ26= 0, at level of significance 0.1, without assuming σ1=σ2. Report the outcome of the test and also the 90% CI for μ1−μ2.3. Repeat the above using the assumption that σ1=σ2.
Using R please
I have answered the question below
Please up vote for the same and thanks!!!
Do reach out in the comments for any queries
Answer:
The R snippet is as follows
df=read.table("http://personal.psu.edu/acq/401/Data/SteelStrengthData.txt",
header = T)
boxplot(Value∼Sample, notch=TRUE, data=df)
# we can perform the t test as shoen below
sample1 <- subset(df,df$Sample==1)
sample2 <- subset(df,df$Sample==2)
## variance true
t.test(sample1$Value,sample2$Value,alternative =
"two.sided",conf.level = 0.90,var.equal = TRUE)
## variance false
t.test(sample1$Value,sample2$Value,alternative =
"two.sided",conf.level = 0.90,var.equal = FALSE)
The results are
> t.test(sample1$Value,sample2$Value,alternative = "two.sided",conf.level = 0.90,var.equal = TRUE)
Two Sample t-test
data: sample1$Value and sample2$Value
t = -3.5756, df = 65, p-value = 0.0006655 ## significant
result , as the p value is less than 0.05
alternative hypothesis: true difference in means is not equal to
0
90 percent confidence interval:
-7.186881 -2.613352
sample estimates:
mean of x mean of y
29.79531 34.69543
> ## variance false
> t.test(sample1$Value,sample2$Value,alternative =
"two.sided",conf.level = 0.90,var.equal = FALSE)
Welch Two Sample t-test
data: sample1$Value and sample2$Value
t = -3.6543, df = 56.108, p-value = 0.000569
## significant result , as the p value is less than
0.05
alternative hypothesis: true difference in means is not equal to
0
90 percent confidence interval:
-7.142758 -2.657474
sample estimates:
mean of x mean of y
29.79531 34.69543