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)

4.4 Heights of adults

  1. What is the point estimate for the average height of active individuals? What about the median?

Point estimate of the mean: 171.1 Point estimate of the median: 170.3

  1. What is the point estimate for the standard deviation of the heights of active individuals? What about the IQR?

Point estimate of sd: 9.4 Point estimate of IQR: 177.8 - 163.8 = 14

  1. Is a person who is 1m 80cm (180 cm) tall considered unusually tall? And is a person who is 1m 55cm (155cm) considered unusually short? Explain your reasoning.
(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.

  1. The researchers take another random sample of physically active individuals. Would you expect the mean and the standard deviation of this new sample to be the ones given above? Explain your reasoning.

With another sample I would not expect the same point estimates. They approximate population values, but vary between samples.

  1. The sample means obtained are point estimates for the mean height of all active individuals, if the sample of individuals is equivalent to a simple random sample. What measure do we use to quantify the variability of such an estimate (Hint: recall that SDx¯=σn√)? Compute this quantity using the data from the original sample under the condition that the data are a simple random sample.
sd <- 9.4
n<-507
se<-sd/sqrt(n)
paste("Standard Error: SE = ",round(se,2))
## [1] "Standard Error: SE =  0.42"

4.14 Thanksgiving spending, Part I

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
  1. We are 95% confident that the average spending of these 436 American adults is between $80.31 and $89.11.

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.

  1. This confidence interval is not valid since the distribution of spending in the sample is right skewed.

FALSE. The skew is acceptable for the sample size of 436, so the skew can be overlooked.

  1. 95% of random samples have a sample mean between $80.31 and $89.11.

FALSE. The confidence interval is not about a sample mean.

  1. We are 95% confident that the average spending of all American adults is between $80.31 and $89.11.

TRUE. This is the definition of a 95% Confidence Interval.

  1. A 90% confidence interval would be narrower than the 95% confidence interval since we don’t need to be as sure about our estimate.

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.

  1. In order to decrease the margin of error of a 95% confidence interval to a third of what it is now, we would need to use a sample 3 times larger.

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.).

  1. The margin of error is 4.4.

TRUE. It is the product of (1.96)∗(sd/sqrt(436))

4.24 Gifted children, Part I

  1. Are conditions for inference satisfied?

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

  1. Suppose you read online that children first count to 10 successfully when they are 32 months old, on average. Perform a hypothesis test to evaluate if these data provide convincing evidence that the average age at which gifted children first count to 10 successfully is less than the general average of 32 months. Use a significance level of 0.10.

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
  1. Interpret the p-value in context of the hypothesis test and the data.

p−value=0.0344=3.44% for a population with 32 months and a sample 36 children

  1. Calculate a 90% confidence interval for the average age at which gifted children first count to 10 successfully.
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"
  1. Do your results from the hypothesis test and the confidence interval agree? Explain.

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.

4.26 Gifted children, Part II

  1. Perform a hypothesis test to evaluate if these data provide convincing evidence that the average IQ of mothers of gifted children is different than the average IQ for the population at large, which is 100. Use a significance level of 0.10.

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.

  1. Calculate a 90% confidence interval for the average IQ of mothers of gifted children.
lowerTail = mean - 1.645 * standardError
upperTail = mean + 1.645 * standardError
lowerTail
## [1] 116.4179
upperTail
## [1] 119.9821
  1. Do your results from the hypothesis test and the confidence interval agree? Explain.

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.

4.34 CLT

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.

4.40 CFLBs

  1. What is the probability that a randomly chosen light bulb lasts more than 10,500 hours?
 1 - pnorm(10500,mean=9000,sd=1000)
## [1] 0.0668072
  1. Describe the distribution of the mean lifespan of 15 light bulbs.

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.

  1. What is the probability that the mean lifespan of 15 randomly chosen light bulbs is more than 10,500 hours?
pnorm(10500 - 9000)/(1000/sqrt(15))
## [1] 0.003872983
  1. Sketch the two distributions (population and sampling) on the same scale.
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)

  1. Could you estimate the probabilities from parts (a) and (c) if the lifespans of light bulbs had a skewed distribution?

No. Has to be approximately normal. Also, sample < 30.

4.48 Same observation, different sample size

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.