Edit Problem


Testing samples
|
Moderate


(First (Grade) Test)

Suppose that you have a sample of IQ scores from a set of first graders.

iq <- c(107, 113, 108, 127, 146, 103, 108, 118, 111, 119)

The IQ test score has an approximately normal distibution with a standard deviation of 15 for the population of US first-graders. (Set aside, for now, concerns about the absurdity of testing first graders for intelligence and cultural influences on test scores. Testing kids is silly, we just need it for the problem set up.)

Use R to test whether this sample of students differs from the population mean.

Notice that there is not a built-in function to test for a standard normal. So, instead, we can write one quickly. Notice that this is simply a re-write of the formula that we have been provided in the book. It takes in data -- which will be the vector of IQ scores, a null hypothesis, and a population standard deviation. From this, it produces the sample average, then a z-stat.

The only, possible trick in this function is the abs(.)*-1. Here, we're trying to find the lower critical value, so that no matter if the sample average is greater or smaller than the null, we can compute a p-value in the same way.

z_test <- function(data, null, sd) {
    x_bar <- mean(data)
    z_stat <- (x_bar - null) / (sd / sqrt(length(data)))

    p_val <- pnorm(q = abs(z_stat)*-1, mean = 0, sd=1) * 2
    return(p_val)
}
Solution:

With the function set up as above, it is straightforward to run the function, and come to a conclusion.

Suppose that we will reject the null hypothesis if the p-value is less that 0.05. Then, we simply run:

iq <- c(107, 113, 108, 127, 146, 103, 108, 118, 111, 119)z_test(data=iq, mean=100, sd=15)## [1] 0.0007432799

And so, we reject the null hypothesis that this classroom has an average IQ that is the same as the national population. We must be in Lake Wobegon.