Rstudio confidence interval3/23/2023 ![]() ![]() The syntax for calculating the sampleMean, sampleSD, and SE should be easy enough to understand. We already have our sample of data stored in samp (and we already told R to store the sample size as n), so let’s get the other components for our formula: sampleMean <- mean(samp) To use our formula, we need to know the following: Let’s verify this result with our formula. ![]() Our sample data was called samp and we wanted a 95% interval ( conf.level=0.95).Īs you can see from the output, our confidence interval is: (95.398, 112.837). We told R to get a confidence interval ( confint) based on the t-distribution ( t.test). (sample mean) +/- (t * SE) where SE = sd/sqrt(n) confint( t.test(samp, conf.level = 0.95)) # mean of x lower upper level This confidence interval is theory-based – it uses the formula we derived in class: Without any explanation, let me show you the syntax to construct a 95% confidence interval in R. Let’s take a look at a Q-Q plot: qqnorm(samp, ylab = "n = 16") qqline(samp, ylab = "n = 16")īased on this Q-Q plot, suppose we’re willing to believe the population distribution is normal (which it is in this case). With such a small sample size, this dotplot doesn’t really tell us what shape to expect for the population distribution. We can take a quick look at our sample data by plotting a dotplot: # cex sets the size of the dots dotPlot(samp, cex=. We’ll use set.seed() to ensure we get the same sample each time we run this lab: n <- 16 # Set size of our sample set.seed( 3141) # Set random number seed # Take sample of size n from our population distribution Let’s take a random sample of n = 16 adults from the “unknown” population. If you’re interested in this unknown population distribution, you might take a random sample of adults and measure their IQ scores. Suppose you don’t know the shape, mean, or standard deviation of the distribution of IQ scores. If we wanted to calculate probabilities under this normal distribution, we could use the xpnorm() command: plotDist( "norm", params= list( mean= 100, sd= 16), col= "steelblue", lw= 5) IQ scores are normally distributed with a mean of 100 and a standard deviation of 16. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |