library(DATA606)
##
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics
## This package is designed to support this course. The text book used
## is OpenIntro Statistics, 3rd Edition. You can read this by typing
## vignette('os3') or visit www.OpenIntro.org.
##
## The getLabs() function will return a list of the labs available.
##
## The demo(package='DATA606') will list the demos that are available.
##
## Attaching package: 'DATA606'
## The following object is masked from 'package:utils':
##
## demo
library(ggplot2)
Point estimate of the mean: 171.1 Point estimate of the median: 170.3
Point estimate of sd: 9.4 Point estimate of IQR: 177.8 - 163.8 = 14
(180 - 171.1)/9.4
## [1] 0.9468085
(155 - 171.1)/9.4
## [1] -1.712766
For different answers, lets define unusual as within 1 standard deviation. If so then our range of usual is 161.7 - 180.5.
180cm is not unusual.
155cm is unusual.
With another sample I would not expect the same point estimates. They approximate population values, but vary between samples.
sd <- 9.4
n<-507
se<-sd/sqrt(n)
paste("Standard Error: SE = ",round(se,2))
## [1] "Standard Error: SE = 0.42"
The 2009 holiday retail season, which kicked off on November 27, 2009 (the day after Thanksgiving), had been marked by somewhat lower self-reported consumer spending than was seen during the comparable period in 2008. To get an estimate of consumer spending, 436 randomly sampled American adults were surveyed. Daily consumer spending for the six-day period after Thanksgiving, spanning the Black Friday weekend and Cyber Monday, averaged $84.71. A 95% confidence interval based on this sample is ($80.31, $89.11). Determine whether the following statements are true or false, and explain your reasoning.
tgSpending <- read.csv("https://raw.githubusercontent.com/ahmshahparan/Homework_4.14/master/thanksgiving_spend.csv")
hist(tgSpending$spending)
summary(tgSpending$spending)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5.719 49.177 75.792 84.707 112.255 282.803
sd(tgSpending$spending)
## [1] 46.92851
FALSE. We know 100% for certain that the average spending costs of these 436 American adults is between $80.31 and $89.11. The point estimate is always in the confidence interval.
FALSE. The skew is acceptable for the sample size of 436, so the skew can be overlooked.
FALSE. The confidence interval is not about a sample mean.
TRUE. This is the definition of a 95% Confidence Interval.
TRUE. If we do not need to be as sure, then we can use a lower number for confidence interval. The range would also be smaller vs. a 95% confidence interval.
FALSE. The sample size needs to be 9x larger (3^2) to decrease the error by 1/3 (In the calculation of the standard error, we divide the standard deviation by the square root of the sample size.).
TRUE. It is the product of (1.96)∗(sd/sqrt(436))
Yws, independence - less than 10% of the total population skew - from sample, doesn’t appear there are significant outliers indicating underlying pop. skewed sample > 30
Null hypothesis : The true population mean is 32 Alt hypothesis : The true population mean is not 32
n = 36
x = 32
mean = 30.69
sd = 4.31
standardError = sd/sqrt(n)
Z = (mean-x)/standardError
p = pnorm(Z,lower.tail = TRUE)
p
## [1] 0.0341013
p−value=0.0344=3.44% for a population with 32 months and a sample 36 children
mu<-30.69
front_tail<-mu + 1.65 * standardError
back_tail<-mu - 1.65 * standardError
paste("decreased_mean_sample=",back_tail,",increased_mean_sample=",front_tail)
## [1] "decreased_mean_sample= 29.50475 ,increased_mean_sample= 31.87525"
Results from the hypothesis test and the confidence interval seem to agree. We are 90% confident that the average age at which gifted children first count to 10 is between 29.5 and 31.9 months. This is lower than the average age for all children at 32 months.
H0 - null hypotheses: μ=100
HA - alternative hypotheses: μ≠100
mean = 118.2
standardError = 6.5/sqrt(36)
z <- (mean - 100)/(6.5/sqrt(36))
1 - pnorm(z)
## [1] 0
Thats a big Z, probability around 0. Thats smaller than our significance level. I reject null hypothesis for the alternative hypothesis.
lowerTail = mean - 1.645 * standardError
upperTail = mean + 1.645 * standardError
lowerTail
## [1] 116.4179
upperTail
## [1] 119.9821
Results from the hypothesis test and the confidence interval seem to agree. We are 90% confident that the average IQ of mothers of gifted children is between 116.4 and 120. This is significantly above population average of 100.
Define the term “sampling distribution” of the mean, and describe how the shape, center, and spread of the sampling distribution of the mean change as sample size increases.
The sampling distribution of the mean is the distribution of sample means of multiple samples. Per the Central Limit Theorem, it can be approximated by a normal model. As sample size increases the normal approximation becomes better and the spread of the sampling distribution of the mean becomes narrower.
1 - pnorm(10500,mean=9000,sd=1000)
## [1] 0.0668072
Could be anything, sample size is not big enough to predict any outcome; central limit theorom applies, if anything it should be near normal distribution.
pnorm(10500 - 9000)/(1000/sqrt(15))
## [1] 0.003872983
par(mfrow = c(2, 1))
xsample <- 7000:11000
ysample <- dnorm(xsample,mean=9000,sd=1000)
xbarsample <- 7000:11000
ybarsample <- dnorm(xbarsample,mean=9000,sd=se)
plot(xsample,ysample)
plot(xbarsample, ybarsample)
No. Has to be approximately normal. Also, sample < 30.
Suppose you conduct a hypothesis test based on a sample where the sample size is n = 50, and arrive at a p-value of 0.08. You then refer back to your notes and discover that you made a careless mistake, the sample size should have been n = 500. Will your p-value increase, decrease, or stay the same? Explain.
P-value will decrease. Because it is inversely dependent on the square root of the sample size.