# Estabishing values
byp_ss <- 539
byp_m <- 19
byp_sd <- 10
ang_ss <- 847
ang_m <- 18
ang_sd <- 9
# Calculating standard error
byp_error <- qnorm(0.95) * byp_sd / sqrt(byp_ss)
ang_error <- qnorm(0.95) * ang_sd / sqrt(ang_ss)
# Calculating 90% confidence interval for bypass
byp_m + byp_error
## [1] 19.70849
byp_m - byp_error
## [1] 18.29151
This has a difference of 1.41698
# Calculating 90% confidence interval for angiography
ang_m + ang_error
## [1] 18.50866
ang_m - ang_error
## [1] 17.49134
This has a difference of 1.01732
The confience interval for angiography is more narrow than bypass surgery.
# Constructing 95% confidence interval for p
prop.test(567,1031)
##
## 1-sample proportions test with continuity correction
##
## data: 567 out of 1031, null probability 0.5
## X-squared = 10.091, df = 1, p-value = 0.00149
## alternative hypothesis: true p is not equal to 0.5
## 95 percent confidence interval:
## 0.5189682 0.5805580
## sample estimates:
## p
## 0.5499515
We reject the null hypothesis that the probability is 0.5 because it is not within the 95% confidence interval of 0.519-0.581. The proportion of adults who believe that education is essential for success fall within this interval.
# Calculating range
range <- 200 - 30
# Calculating standard deviation
sd <- range / 4
# Calculating Z score
z = qnorm(.975)
# Sovling given with confidence interval
n = ((z*sd) / 5)^2
n
## [1] 277.5454
The sample size of books should be 278, rounding up.
# Writing function to calculate find t statitstic
func_t_stat <- function(x_bar, mu, sd, n){
return((x_bar - mu) / (sd / sqrt(n)))
}
# Calculating t statistic
t_stat <- func_t_stat(x_bar = 410, mu = 500, sd = 90, n = 9)
# Two tailed test
two_tail <- 2*pt(t_stat, df = n-1)
two_tail
## [1] 0.002945867
We reject the null hypothesis that the income mean for females is 500 since the P score is below .05.
# lower tail test to find p value below 500
lower_tail <- pt(t_stat, df = n-1)
lower_tail
## [1] 0.001472934
We reject the null hypothesis that the income mean for females is greater than 500 since the P score is below .05.
# upper tail test to find p value above 500
upper_tail <- pt(t_stat, df= n-1, lower.tail = FALSE)
upper_tail
## [1] 0.9985271
We fail to reject the null hypothesis that the mean income for females is less than 500 since the p score is above .05.
# Calculating T value for Jones
t_jones <- ((519.5 - 500)/ 10)
t_jones
## [1] 1.95
# Calculating T value for Smith
t_smith <- ((519.7 - 500)/ 10)
t_smith
## [1] 1.97
# Calculating P score for Jones
p_jones <- 2*pt(t_jones , df = 999, lower.tail = FALSE)
p_jones
## [1] 0.05145555
# Calculating P score for Smith
p_smith <- 2*pt(t_smith, df = 999, lower.tail = FALSE)
p_smith
## [1] 0.04911426
At the .05 level, Jones' result is not statistically significant since the P score is greater than .05, where as Smith's result is statisitically significant as the P score is below .05.
These results exemplify the absolute importance of reporting the P score in comparison to the .05 significance level because even though the the results were so similar and close, the actual P score reveals their true significance which lead us to either reject or fail to reject the null hypothesis. Without reporting the actual P score this realization may not be met.
# Creating gas tax dataframe
gas_taxes <- c(51.27, 47.43, 38.89, 41.95, 28.61, 41.29, 52.19, 49.48, 35.02, 48.13, 39.28, 54.41, 41.66, 30.28, 18.49, 38.72, 33.41, 45.02)
# Creating a one-sample T test at 95% confidence level
t.test(gas_taxes, mu = 45, alternative = 'less')
##
## One Sample t-test
##
## data: gas_taxes
## t = -1.8857, df = 17, p-value = 0.03827
## alternative hypothesis: true mean is less than 45
## 95 percent confidence interval:
## -Inf 44.67946
## sample estimates:
## mean of x
## 40.86278
We reject the null hypothesis in favor of the alternative that gas price in 2005 were less than 45 cents since the P value is less than the .05 significance level.