D606 Stats HW CH04

Kyle Gilde

Mar. 11, 2017

Chapter 4 Foundations for Inference

Practice: 4.3, 4.13, 4.23, 4.25, 4.39, 4.47

Graded: 4.4, 4.14, 4.24, 4.26, 4.34, 4.40, 4.48

Load Packages
knitr::opts_chunk$set(#echo=FALSE, 
                      warning=FALSE, 
                      message=FALSE,
                      tidy=F,
                      collapse = T,
                      #comment = "",
                      dev="png", 
                      dev.args=list(type="cairo"))
#https://cran.r-project.org/web/packages/prettydoc/vignettes/
#https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf

load.packages <- c("prettydoc", "knitr", "DATA606")

ipak <- function(pkg){
    #FUNCTION SOURCE: https://gist.github.com/stevenworthington/3178163
    new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
    if (length(new.pkg)) 
        install.packages(new.pkg, dependencies = TRUE)
    sapply(pkg, require, character.only = TRUE, quietly = TRUE, warn.conflicts = FALSE)
}

ipak(load.packages)
## 
## 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.
## prettydoc     knitr   DATA606 
##      TRUE      TRUE      TRUE

4.4 Heights of adults.

Researchers studying anthropometry collected body girth measurements and skeletal diameter measurements, as well as age, weight, height and gender, for 507 physically active individuals. The histogram below shows the sample distribution of heights in centimeters.

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

What about the median? 170.3

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

What about the IQR?

177.8 - 163.8
## [1] 14
  1. Is a person who is 1m 80cm (180 cm) tall considered unusually tall? This person is not unusually tall because his/her height has a z-score of less than one and is within one standard deviation of the mean. In a normal distribution, approximately 34% of the sample is at least this extreme.
v1 <- 180
xbar <- 171.1
s <- 9.4
#person 1 zscore
(v1 - xbar)/s
## [1] 0.9468085
pnorm(v1, xbar, s, lower.tail = F) * 2
## [1] 0.3437364

And is a person who is 1m 55cm (155cm) considered unusually short? Explain your reasoning. This person is more unusally short because her z-score of -1.71 is further away from the mean. Only 9% of the sample is at least this extreme

v2 <- 155
#person 2 zscore
(v2 - xbar)/s
## [1] -1.712766
pnorm(v2, xbar, s) * 2
## [1] 0.08675561
  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. No, they would not exactly match. Both point estimates could be found on the sampling distribution.
  2. 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)? Compute this quantity using the data from the original sample under the condition that the data are a simple random sample. The standard error
s / sqrt(507)
## [1] 0.4174687

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.

  1. We are 95% confident that the average spending of these 436 American adults is between $80.31 and $89.11. False. Confidence intervals pertain to the population parameter. We are 95% confident that the average post-Thanksgiving spending for American adults is between $80.31 and $89.11.

  2. This confidence interval is not valid since the distribution of spending in the sample is right skewed. False. Because we have a large sample size, we can be more lenient with the not-strongly-skewed condition.

  3. 95% of random samples have a sample mean between $80.31 and $89.11. False. If repeated samples were taken and the 95% confidence interval was computed for each sample, 95% of the intervals would contain the population mean.

  4. We are 95% confident that the average spending of all American adults is between $80.31 and $89.11. True. This is the correct interpretation of the CI

  5. 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. The critical value would be less, which would create a smaller margin of error when it’s multipled by the SE.

  6. 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. Because the SE and therefore the ME is divided by the square root of the sample size, we would need to take a sample 9 times larger.

n <- 436
xbar <- 84.71 
ci1 <- 80.31 
ci2 <- 89.11
me <- xbar - ci1
zstar <- 1.96
se <- me / zstar
s <- se * sqrt(n)

n2 <- n * 9
me2 <- zstar * s/sqrt(n2)
me/me2
## [1] 3
  1. The margin of error is 4.4. True. The ME is calculated by adding and substracting it to the point estimate.
xbar - ci1
## [1] 4.4

4.24 Gifted children, Part I.

Researchers investigating characteristics of gifted children collected data from schools in a large city on a random sample of thirty-six children who were identified as gifted children soon after they reached the age of four. The following histogram shows the distribution of the ages (in months) at which these children first counted to 10 successfully. Also provided are some sample statistics.

  1. Are conditions for inference satisfied? Yes
  • The observations are independent since they are from a random sample of less than 10% of the population.
  • The sample size is greater than or equal to 30
  • The histogram doesn’t a strong skew
  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.

\(H_{0}: \mu_{gifted}=32\)

\(H_{A}: \mu_{gifted}<32\)

n <- 36
min_months <- 21
xbar <- 30.69
s <- 4.31
max_months <- 39
H0 <- 32
se <- s/sqrt(n)
sign_level <- .1

pvalue <- pnorm(xbar, H0, se)

paste("pvalue =", pvalue)
## [1] "pvalue = 0.0341012990635018"
ifelse(pvalue < sign_level, "Reject the null hypothesis", "Fail to reject the null hypothesis")
## [1] "Reject the null hypothesis"
  1. Interpret the p-value in context of the hypothesis test and the data. Because the p-value is less than the significance level, we reject the null hypothesis that gifted children learn to count to 10 at the same age of the general population.

  2. Calculate a 90% confidence interval for the average age at which gifted children first count to 10 successfully.

cv <- abs(qnorm(sign_level))
me <- cv * se
c(xbar - me, xbar + me)
## [1] 29.76942 31.61058
  1. Do your results from the hypothesis test and the confidence interval agree? Explain. No, they agree. The general average is outside of the 90% confidence interval for the gifted children. Likewise, the small p-value indicates that gifted average is more extreme than the .1 significance level

4.26 Gifted children, Part II.

Exercise 4.24 describes a study on gifted children. In this study, along with variables on the children, the researchers also collected data on the mother’s and father’s IQ of the 36 randomly sampled gifted children. The histogram below shows the distribution of mother’s IQ. Also provided are some sample statistics.

  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.

\(H_{0}: \mu_{moms_gifted} = 100\) \(H_{A}: \mu_{moms_gifted} \neq 100\)

H0 <- 100
n <- 36
xbar <-  118.2
sd <- 6.5
sign_level <- .1

se <- sd/sqrt(n)
pvalue <- pnorm(xbar, H0, se, lower.tail = F) * 2
paste("pvalue =", pvalue)
## [1] "pvalue = 2.4404400811951e-63"

ifelse(pvalue < sign_level, "Reject the null hypothesis", "Fail to reject the null hypothesis")
## [1] "Reject the null hypothesis"
  1. Calculate a 90% confidence interval for the average IQ of mothers of gifted children.
cv <- abs(qnorm(sign_level))

lower_value <- xbar - cv * se
upper_value <- xbar + cv * sd
c(lower_value, upper_value)
## [1] 116.8117 126.5301
  1. Do your results from the hypothesis test and the confidence interval agree? Explain. Yes, the p-value is much less than \(\alpha\), and the \(H_{0}\) lies outside of the 90% confidence interval.

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.

A sampling distribution is the distribution of means taken from samples of size n from a population, and the concept is central to statistical inference. As the size of the samples increases, the shape of the sampling distribution becomes more normal, and it becomes more centered over the population mean.

4.40 CFLBs.

A manufacturer of compact fluorescent light bulbs advertises that the distribution of the lifespans of these light bulbs is nearly normal with a mean of 9,000 hours and a standard deviation of 1,000 hours.

  1. What is the probability that a randomly chosen light bulb lasts more than 10,500 hours?
mu <- 9000
sigma <- 1000
threshold <- 10500

pnorm(threshold, mu, sigma, lower.tail = F)
## [1] 0.0668072
  1. Describe the distribution of the mean lifespan of 15 light bulbs. Since the sample size isn’t very large, the sampling distribution will likely be vaguely normal and may be centered at the population mean.

  2. What is the probability that the mean lifespan of 15 randomly chosen light bulbs is more than 10,500 hours?

n <- 15
se <- sigma/sqrt(n)
pnorm(threshold, mu, se, lower.tail = F)
## [1] 3.133452e-09
  1. Sketch the two distributions (population and sampling) on the same scale.
pop_size <- 10^6
pop_distro <- rnorm(pop_size, mu, sigma)


samples <- 5000
n <- 15

sample_means15 <- rep(NA, samples)
for (i in 1:samples){
  samp <- sample(pop_distro, n)
  sample_means15[i] <- mean(samp)
}

hist(pop_distro, xlim = c(4000, 14000))

hist(sample_means15, xlim = c(4000, 14000))

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

(a) No, the accuracy of the pnorm function is dependent upon the distribution being nearly normal

(c) No, since we have a small sample, we can’t be more lenient with the non-skewed condition.

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.

The p-value will decrease because the increase in n will decrease the standard error. The new SE will be about one third of the old one. This will make the observed point estimate much more of an extreme value, which means that the p-value will be smaller

Practice Problems

4.23 Nutrition labels.

The nutrition label on a bag of potato chips says that a one ounce (28 gram) serving of potato chips has 130 calories and contains ten grams of fat, with three grams of saturated fat. A random sample of 35 bags yielded a sample mean of 134 calories with a standard deviation of 17 calories. Is there evidence that the nutrition label does not provide an accurate measure of calories in the bags of potato chips? We have verified the independence, sample size, and skew conditions are satisfied.

H0 <- 130
n <- 35
xbar <- 134
s <- 17

se <- s/sqrt(n)
zscore <- (xbar - H0) / se
pvalue <- pnorm(xbar, H0, se, lower.tail = F) * 2
pvalue 
## [1] 0.1639167

normalPlot(bounds=c(-zscore, zscore), tails = T)

4.25 Waiting at an ER, Part III.

The hospital administrator mentioned in Exercise 4.13 randomly selected 64 patients and measured the time (in minutes) between when they checked in to the ER and the time they were first seen by a doctor. The average time is 137.5 minutes and the standard deviation is 39 minutes. She is getting grief from her supervisor on the basis that the wait times in the ER has increased greatly from last year’s average of 127 minutes. However, she claims that the increase is probably just due to chance.

  1. Are conditions for inference met? Note any assumptions you must make to proceed.

  2. Using a significance level of \(\alpha\) = 0.05, is the change in wait times statistically significant? Use a two-sided test since it seems the supervisor had to inspect the data before she suggested an increase occurred.

H0 <- 127
n <- 64
xbar <- 137.5
s <- 39
alpha <- .05

se <- s/sqrt(n)
zscore <- (xbar - H0) / se
pvalue <- (1 - pnorm(zscore)) * 2
pvalue 
## [1] 0.03125224

ifelse(pvalue < alpha, "Reject the null hypothesis", "Fail to reject the null hypothesis")
## [1] "Reject the null hypothesis"

normalPlot(bounds=c(-zscore, zscore), tails = T)

4.39 Weights of pennies.

The distribution of weights of United States pennies is approximately normal with a mean of 2.5 grams and a standard deviation of 0.03 grams.

  1. What is the probability that a randomly chosen penny weighs less than 2.4 grams?
mu <- 2.5
sigma <- .03
x <- 2.4

pnorm(x, mu, sigma)
## [1] 0.0004290603
  1. Describe the sampling distribution of the mean weight of 10 randomly chosen pennies.

  2. What is the probability that the mean weight of 10 pennies is less than 2.4 grams?

xbar <- 2.4
n <- 10
se <- sigma/sqrt(n)

pnorm(xbar, mu, se)
## [1] 2.797279e-26
  1. Sketch the two distributions (population and sampling) on the same scale.

  2. Could you estimate the probabilities from (a) and (c) if the weights of pennies had a skewed

distribution?