Created
May 17, 2017 18:53
-
-
Save earino/c77b44bba17d96d8ee41ba387aef8e0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> library(MASS) # load the MASS package | |
> height.response = na.omit(survey$Height) | |
> n = length(height.response) | |
> s = sd(height.response) # sample standard deviation | |
> SE = s/sqrt(n); SE # standard error estimate | |
[1] 0.6811677 | |
> | |
> print(paste("Standard Error:", SE)) | |
[1] "Standard Error: 0.68116773214787" | |
> | |
> E = qt(.975, df=n-1)*SE # margin of error | |
> | |
> print(paste("Margin of Error:", E)) | |
[1] "Margin of Error: 1.34287767542194" | |
> | |
> xbar = mean(height.response) # sample mean | |
> xbar + c(-E, E) | |
[1] 171.0380 173.7237 | |
> | |
> # OR THE EASY WAY | |
> | |
> t.test(height.response) | |
One Sample t-test | |
data: height.response | |
t = 253.07, df = 208, p-value < 2.2e-16 | |
alternative hypothesis: true mean is not equal to 0 | |
95 percent confidence interval: | |
171.0380 173.7237 | |
sample estimates: | |
mean of x | |
172.3809 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment