In: Statistics and Probability
mean(data2$absent)
[1] 3
>gmean <- prod(data2$absent)^(1/length(data2$absent))
> gmean
[1] 2.798166
>median(data2$absent)
[1] 2.5
> mode <- names(table(data2$absent)) [table(data2$absent)==max(table(data2$absent))]
> mode
[1] "2"
> var(data2$absent)
[1] 1.6
> sd(data2$absent)
[1] 1.264911
> cv <- abs(sd(data2$absent)/mean(data2$absent))
> cv
[1] 0.421637
> IQR(data2$absent, type=6)
[1] 2.25
Pie Chart with Percentages
slices <- c(50, 16.6666667, 16.6666667, 16.6666667)
lbls <- c("2 days absent", "3 days absent", "4 days absent", "5 days absent")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct) # add percents to labels
lbls <- paste(lbls,"%",sep="") # ad % to labels
pie(slices,labels = lbls, col=rainbow(length(lbls)),
main="Pie Chart of Absences")
x <- data2$absent
> h<-hist(x, breaks=10, col="magenta", xlab="# of student absences",
+ main="Histogram of student absences")
> xfit<-seq(min(x),max(x),length=40)
> yfit<-dnorm(xfit,mean=mean(x),sd=sd(x))
> yfit <- yfit*diff(h$mids[1:2])*length(x)
> lines(xfit, yfit, col="blue", lwd=2)
Suppose someone claims that the population mean is 5 days absent (?: ? =5). What is the alternative hypothesis? Can you reject the null hypothesis at the 5‐percent and 1‐percent levels of significance? Use the critical value, p‐value, and confidence interval approaches both “by hand” and with R. In the “by hand” approach, you can use R (or a statistical table) to get the critical values. ????
A= {2, 3, 2, 4, 2, 5}
Null Hypothesis H0: ? =5
Alternative Hypothesis H1; ? 5
Sample mean = (2 + 3 + 2 + 4 + 2 + 5) / 6 = 3
Sample variance = [ (2 - 3)2 + (3 - 3)2 + (2 - 3)2 + (4 - 3)2 + (2 - 3)2 + (5 - 3)2 ] / 5
= 1.6
Sample Standard deviation, s = = 1.264911
Standard error, SE = s / = 1.264911 / = 0.5163978
Test statistic, t = (3 - 5) / 0.5163978 = -3.872983
Degree of freedom = n-1 = 6 - 1 = 5
For two tail test, P-value = 2 * P(t < -3.872983) = 0.01172482
P-value approach - Since, p-value is less than 0.05 significance level, we reject null hypothesis H0 at 5% significance level and conclude that there is strong evidence that ? 5.
Since, p-value is greater than 0.01 significance level, we fail to reject null hypothesis H0 at 1% significance level and conclude that there is no strong evidence that ? 5.
Critical value of t at df = 5 and 5‐percent and 1‐percent levels of significance are 2.57 and 4.032. That is we reject H0 if t <-2.57 or t > 2.57 at 5% significance level. And we reject H0 if t <-4.032 or t > 4.032 at 1% significance level.
Critical value approach -
Since, test statistic lie in the critical region we reject null hypothesis H0 at 5% significance level and conclude that there is strong evidence that ? 5.
Since, test statistic does lie in the critical region, we fail to reject null hypothesis H0 at 1% significance level and conclude that there is no strong evidence that ? 5.
For 5% significance level ,
Margin of error = t * SE = 2.57 * 0.5163978 = 1.327142
95% confidence interval is,
(3 - 1.327142, 3 + 1.327142)
(1.672858, 4.327142)
Since hypothesized mean 5 does not lie in the 95% confidence interval, we conclude that there is strong evidence that ? 5.
For 1% significance level ,
Margin of error = t * SE = 4.032 * 0.5163978 = 2.082116
99% confidence interval is,
(3 - 2.082116, 3 + 2.082116)
(0.917884, 5.082116)
Since hypothesized mean 5 lie in the 99% confidence interval, we conclude that there is no strong evidence that ? 5.
Using R,
For 5% significance level ,
t.test(A, mu = 5)
One Sample t-test
data: A
t = -3.873, df = 5, p-value = 0.01172
alternative hypothesis: true mean is not equal to 5
95 percent confidence interval:
1.672557 4.327443
sample estimates:
mean of x
3
For 1% significance level ,
t.test(A, mu = 5, conf.level = 0.99)
One Sample t-test
data: A
t = -3.873, df = 5, p-value = 0.01172
alternative hypothesis: true mean is not equal to 5
99 percent confidence interval:
0.9178103 5.0821897
sample estimates:
mean of x
3