Working backwards, Part II. (5.24, p. 203) A 90% confidence interval for a population mean is (65, 77). The population distribution is approximately normal and the population standard deviation is unknown. This confidence interval is based on a simple random sample of 25 observations. Calculate the sample mean, the margin of error, and the sample standard deviation.

n <- 25
lower <- 65
upper <- 77
p <- 0.90 

paste('Sample Mean is', ( (lower+ upper)/2 ) )
## [1] "Sample Mean is 71"
paste('Margin of Error (ME) is', ( (upper - lower)/2 ) )
## [1] "Margin of Error (ME) is 6"
# To calculate the sample standard deviation ; we will use the formula as below:
# ME = t * SE:
# SE = ME / t  ; where t = qt( (p + (1 - p)/2), (n-1) ) 
# SD = SE * sqrt(n)

SE <-  ( (upper - lower)/2    /  ( qt( (p + (1 - p)/2), (n-1)) ) )
SD <- SE * sqrt(n)

paste('Sample standard deviation (SD) is', SD )
## [1] "Sample standard deviation (SD) is 17.5348145569379"

SAT scores. (7.14, p. 261) SAT scores of students at an Ivy League college are distributed with a standard deviation of 250 points. Two statistics students, Raina and Luke, want to estimate the average SAT score of students at this college as part of a class project. They want their margin of error to be no more than 25 points.

  1. Raina wants to use a 90% confidence interval. How large a sample should she collect?

    # To calculate the sample standard deviation ; we will use the formula as below:
    # SD = SE * sqrt(n)  => SE = SD / sqrt(n)
    # ME = t * SE   => ME = t * (SD / sqrt(n)) =>  ME / t = (SD / sqrt(n))
    # resolving for n in above we get =>  n =  (( t * SD) / ME ) ^2
    
    t <- 1.65  # 90% Confidence interval
    ME <- 25
    SD <- 250
    
    n <- (( t * SD) / ME ) ^2 
    
    paste('Sample size (n) must be ',  ceiling(n) )
    ## [1] "Sample size (n) must be  273"
  2. Luke wants to use a 99% confidence interval. Without calculating the actual sample size, determine whether his sample should be larger or smaller than Raina’s, and explain your reasoning.

    Luke needs a larger sample;For a higher confidence its required that the sample is representative of the population.

  3. Calculate the minimum required sample size for Luke.

    # To calculate the sample standard deviation ; we will use the formula as below:
    # SD = SE * sqrt(n)  => SE = SD / sqrt(n)
    # ME = t * SE   => ME = t * (SD / sqrt(n)) =>  ME / t = (SD / sqrt(n))
    # resolving for n in above we get =>  n =  (( t * SD) / ME ) ^2
    
    t <- 2.575  # 99% Confidence interval
    ME <- 25
    SD <- 250
    
    n <- (( t * SD) / ME ) ^2 
    
    paste('Sample size (n) must be ',  ceiling(n) )
    ## [1] "Sample size (n) must be  664"

High School and Beyond, Part I. (7.20, p. 266) The National Center of Education Statistics conducted a survey of high school seniors, collecting test data on reading, writing, and several other subjects. Here we examine a simple random sample of 200 students from this survey. Side-by-side box plots of reading and writing scores as well as a histogram of the differences in scores are shown below.

  1. Is there a clear difference in the average reading and writing scores?

    Answer: There seems no clear difference in the average reading and writing scores. The box plot shows the mean scores are fairly close to each other. and ths ditribution from histogram seems normal.

  2. Are the reading and writing scores of each student independent of each other?

    Answer: reading and writing scores of each student are independent of each other.

  3. Create hypotheses appropriate for the following research question: is there an evident difference in the average scores of students in the reading and writing exam?

    Answer: The hypotheses could be as follows:

    H(0): The difference of average in between reading and writing equal zero.
    H(A): The difference of average in between reading and writing NOT equal zero.

  4. Check the conditions required to complete this test.

    Answer: Conditions checked are (1) the Observations are independent and (2) the Distribution looks normal distribution; Both are satisfied.

  5. The average observed difference in scores is \({ \widehat { x } }_{ read-write }=-0.545\), and the standard deviation of the differences is 8.887 points. Do these data provide convincing evidence of a difference between the average scores on the two exams?

    SD.diff <- 8.887
    mean.diff <- -0.545
    n <- 200
    
    SE.diff <- SD.diff / sqrt(n)
    
    # Compute T:
    t <- (mean.diff - 0) / SE.diff
    
    df <- n - 1
    
    p <- pt(t, df)
    
    paste('p-value is', p)
    ## [1] "p-value is 0.193418237099674"

    Answer: We fail to reject the null hypothesis as p-value > 0.05 .

  6. What type of error might we have made? Explain what the error means in the context of the application.

    Answer: A type II (Incorrectly reject the alternative hypothesis) error by rejecting the alternative hypothesis HA.

  7. Based on the results of this hypothesis test, would you expect a confidence interval for the average difference between the reading and writing scores to include 0? Explain your reasoning.

    Answer: Yes, we can expect a confidence interval for the average difference between reading and writing scores to include 0; confidence interval of 0 would mean the differnece could be on one side or another.


Fuel efficiency of manual and automatic cars, Part II. (7.28, p. 276) The table provides summary statistics on highway fuel economy of cars manufactured in 2012. Use these statistics to calculate a 98% confidence interval for the difference between average highway mileage of manual and automatic cars, and interpret this interval in the context of the data.

Answer: The hypotheses for this test are as follows: H0: The difference of average miles is equal to zero.
HA: The difference of average miles is NOT equal to zero.

n <- 26
mean.auto <- 22.92
sd.auto <- 5.29
mean.manual <- 27.88
sd.manual <- 5.01
# Difference in sample means:
mean.diff <- mean.auto - mean.manual
# Compute t:
SE.diff <- ( (sd.auto ^ 2 / n) + ( sd.manual ^ 2 / n) ) ^ 0.5
t <- (mean.diff - 0) / SE.diff
df <- n - 1
p <- pt(t,   df)

paste('p-value is', p)
## [1] "p-value is 0.000948685260185651"

We reject the null hypothesis as p-value < 0.05 .


Email outreach efforts. (7.34, p. 284) A medical research group is recruiting people to complete short surveys about their medical history. For example, one survey asks for information on a person’s family history in regards to cancer. Another survey asks about what topics were discussed during the person’s last visit to a hospital. So far, as people sign up, they complete an average of just 4 surveys, and the standard deviation of the number of surveys is about 2.2. The research group wants to try a new interface that they think will encourage new enrollees to complete more surveys, where they will randomize each enrollee to either get the new interface or the current interface. How many new enrollees do they need for each interface to detect an effect size of 0.5 surveys per enrollee, if the desired power level is 80%?

t <-  1.28  # 80% Confidence interval
ME <- 0.5
SD <- 2.2
    
n <- (( t * SD) / ME ) ^2 
    
paste('Sample size (n) must be ',  ceiling(n) )
## [1] "Sample size (n) must be  32"

Work hours and education. The General Social Survey collects data on demographics, education, and work, among many other characteristics of US residents.47 Using ANOVA, we can consider educational attainment levels for all 1,172 respondents at once. Below are the distributions of hours worked by educational attainment and relevant summary statistics that will be helpful in carrying out this analysis.

  1. Write hypotheses for evaluating whether the average number of hours worked varies across the five groups.

    Answer: The hypotheses for this test is:
    H0: The difference of ALL averages is equal.
    HA: There is one average that is NOT equal to the other ones.

  2. Check conditions and describe any assumptions you must make to proceed with the test.

    Answer: Conditions checked are (1) the Observations are independent and (2) the Distribution does not looks normal distribution; NOt all condition are met here.

  3. Below is part of the output associated with this test. Fill in the empty cells.

    n <- 1172
    k <- 5
    mean.total <- 40.45
    
    df.total <- n - 1
    df.degree <- k -1
    df.residuals <- df.total -  df.degree
    
    education.df <- data.frame(n=c(121, 546,97,253,155)
                               , sd=c(15.81,14.97,18.1,13.62,15.51)
                               , mean=c(38.67,39.6,41.39,42.55,40.85))
    
    
    sum.sq.degree <- sum( education.df$n * (education.df$mean - mean.total)^2 )
    sum.sq.total <-   sum.sq.degree + 267382
    
    mean.sq.residuals<- (1 / df.residuals) * 267382
    
    f.value.degree <- round( 501.54 / mean.sq.residuals , 4)
    
    #making the final table
    degree <- c(df.degree, sum.sq.degree,501.54,f.value.degree, 0.0682)
    residuals <- c(df.residuals, 267382,mean.sq.residuals, 0,0 )
    total <- c(df.total, sum.sq.total, 0, 0, 0)
    
    output.df <- as.data.frame(rbind(degree,residuals, total ))

    colnames(output.df) <- c( 'Df','SumSq','MeanSq', 'F-value', 'Pr(>f)' )

    kable(output.df,  row.names = T)
Df SumSq MeanSq F-value Pr(>f)
degree 4 2004.101 501.5400 2.189 0.0682
residuals 1167 267382.000 229.1191 0.000 0.0000
total 1171 269386.101 0.0000 0.000 0.0000
  1. What is the conclusion of the test?

    Answer: We cannot reject the null hypothesis as p-value > 0.05 .