R Project #1: Hypothesis Testing With t-Test
QUESTION:
Consider the gain in weight of 19 female rats between 28 and 84 days after birth. 12 were fed on high protein diet and 7 on a low protein diet. Using the data given below, test the hypothesis that there is no difference in weight gain between female rats raised on a high-protein diet versus those raised on a low-protein diet. Use a significance level of 𝛼 = 0.05 and assume equal variances.
Weight Gain Measured in Grams:High protein: 134,146,104,119,124,161,107,83,113,129,97,12
Low protein: 70,118,101,85,107,132,94
SOLUTION:
The Null Hypothesis here is that there is no weight gain difference between the 2 groups of rats. It will be shown that there is no reason to reject the Null Hypothesis. This will be done using the R code shown below.
#This
will be a test involving two population means
#mu1 is
population mean-of-weight-gain of high protein rats
#mu2 is
population mean-of-weight-gain of low protein rats
# H0: mu1
- mu2 = 0 i.e. no difference in weight gain (THIS IS THE NULL HYPOTHESIS)
#Ha: mu1
- mu2 <>0 therefore, 2-tailed test (THIS IS THE ALTERNATE HYPOTHESIS)
#create
vectors of weight gain in rats
high_protein<-c(134,146,104,119,124,161,107,83,113,129,97,12)
low_protein<-c(70,118,101,85,107,132,94)
#Because each vector has a low number of data points, i.e. n<30,
#a t-test
will be done to test the null hypothesis H0.
#FIRST:determine if high_protein and low_protein are
#normal
or approximately normal by plotting their
#stem and
leaf plots
stem(high_protein)
The decimal point is 2 digit(s) to the right of the |
0 | 8
1 | 00112233
1 | 56
stem(low_protein)
The decimal point is 1 digit(s) to the right of the |
8 | 54
10 | 178
12 | 2
#SECOND: perform a second test to determine if
#high_protein
and low_protein are normal or approximately normal
#by
plotting their histograms
hist(high_protein,main="high
protein",xlab="weight gain")
hist(low_protein,main="low protein",xlab="weight gain")
#in their
histograms, therefore, presume normal populations
#Therefore,
t-test is permissible.
#dof =
degrees of freedom
dof = length(high_protein) + length(low_protein)-2
dof
[1] 17
#perform t-test for the 2 independent samples
t.test(high_protein,low_protein,alternative="two.sided",conf.level=0.95,var.equal=TRUE)
Two
Sample t-test
data: high_protein
and low_protein
t = 0.62634, df = 17, p-value = 0.5394
alternative hypothesis: true difference in means is not
equal to 0
95 percent confidence interval:
-23.09271 42.59271
sample estimates:
mean of x mean of y
110.75 101.00
#The 95%
confidence interval includes i.e. the interval's range is -23.09271 to 42.59271.
#The
p-value is 0.5394, which is much greater than alpha=0.05.
#Therefore, there is insufficient evidence to reject H0, i.e. there is no difference in
#weight
gain between the 2 groups of female rats.
Comments
Post a Comment