0
$\begingroup$

I came across these funnel plots here and tried to reproduce something similar where I have a normally distributed population and I happen to know the true population mean (500000) and standard deviation (13000).

I am aware of these 2 intervals: confidence interval (CI) and tolerance interval. The former's width depends on the sample size whereas the latter's depends on the sample size and the variance in the population.

I came up with the R code below. It produces the following graph.

enter image description here

IMHO the blue line represents the 95% CI depending on the sample size. In other words, the sample mean will fall with 95% probability into this funnel. Would you agree with this?

mu_ <- 500000
sd_ <- 13000
z_value <- qnorm(.975)
max_sample_size = 100
repeats = 2

results <- NULL
upper_and_lower <- NULL

for (sample_size_ in 3:max_sample_size) {
    
    for (sample_number_ in 1:2) {
        
        sample_ <- rnorm(sample_size_, mean=mu_, sd=sd_)
        
        df <- data.frame(
            sample_size = sample_size_
            , mean = mean(sample_)
        )

        results <- rbind(results, df)
        
    }
    
    df <- data.frame(
        sample_size = sample_size_
        , upper = mu_ + (z_value * (sd_/sqrt(sample_size_)))
        , lower = mu_ - (z_value * (sd_/sqrt(sample_size_)))
    )
    upper_and_lower <- rbind(upper_and_lower, df)
}

ggplot() +
    geom_point(data=results, aes(y = mean, x = sample_size)) +
    geom_line(data=upper_and_lower, aes(y = upper, x = sample_size), color = "blue", size=2) +
    geom_line(data=upper_and_lower, aes(y = lower, x = sample_size), color = "blue", size=2) +
    ggplot() +
geom_point(data=results, aes(y = mean, x = sample_size)) +
geom_line(data=upper_and_lower, aes(y = upper, x = sample_size), color = "blue", size=2) +
geom_line(data=upper_and_lower, aes(y = lower, x = sample_size), color = "blue", size=2) +
theme(
    axis.text.x=element_text(size=18, angle=45, vjust=1, hjust=1, face="bold", color="black"),
    axis.text.y=element_text(size=18, face="bold", color="black"),
    axis.title.x=element_text(size=18, face="bold", color="black"),
    axis.title.y=element_text(size=18, face="bold", color="black")
) +
ylab("Sample Means \t\n Red dotted line = population mean") +
geom_hline(yintercept=mu_, linetype="dotted", color = "red", size=2) 
$\endgroup$
1
$\begingroup$

It is not exactly correct to say the blue curves represent the 95% CIs. For a given sample size, the 95% CI would be different for every different observed mean. But, it is correct that any mean will fall within the blue curves with 95% probability.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.