diff --git a/LaBella_02.rmd b/LaBella_02.rmd new file mode 100644 index 0000000..35665dc --- /dev/null +++ b/LaBella_02.rmd @@ -0,0 +1,108 @@ +--- +title: "LaBella_02 Homework" +author: "Rachel LaBella" +date: "September 19, 2016" +output: html_document +--- + +##Question 1 + +###Question 1a +##Say “Vole vasopressin” 10 times as fast as you can. How many times did you trip up? +Only once!! + +###Question 1b +##What is the mean, median, sd, and interquartile range of the sample? +```{r, echo=TRUE} +library(dplyr) +vole_vaso <- c(98,96,94,88,86,82,77,74,70,60, + 59,52,50,47,40,35,29,13,6,5) +mean(vole_vaso) +median(vole_vaso) +sd(vole_vaso) +IQR(vole_vaso) +``` + +###Question 1c +##What is the standard error of the mean (do this with a formula!)? +```{r, echo=TRUE} +std.error <- sd(vole_vaso)/sqrt(length(vole_vaso)) +std.error +``` + +###Question 1d +##What does the standard error of the mean tell you about our estimate of the mean values of the population of vole vassopressin? +The standard error number is an indication of the reliability of the mean itself. The larger the sample size, the smaller the standard error. The smaller the std error, the more reliable our data. + + +###Question 2 +###Question 2a +##Use sample() to get just one resample with a sample size of 10. What is its upper quartile? +``` {r, echo = TRUE} +set.seed(150) +quantile(vole_vaso, probs = 0.75) +sample(vole_vaso, 10, replace = TRUE, prob = NULL) %>% + summary() +``` +The upper quartile for the vole_vaso dataset is 83 with replacement. +When I take one resample with the sample size of 10, the upper quartile is 76.25. + + +###Question 2b +##Build an initial data frame for simulations with the sample sizes 5 through 20. Have 100 simulations per sample size. +``` {r, echo = TRUE} +set.seed(150) +df_vole <- data.frame(samp.size = rep(5:20, times=100)) +df_vole$sim_sample <- 1:nrow(df_vole) +head(df_vole) +``` + +###Question 2c +## Use this data frame to get simulated upper quartiles for each sample size. +```{r, echo = TRUE} +df_vole <- df_vole %>% + group_by(sim_sample) %>% + mutate(quantile_sim = quantile(sample(vole_vaso, size = samp.size, replace = TRUE), probs = 0.75)) %>% + ungroup() +``` + +###Question 2d +##With a plot, make a guesstimate as to the best sample size for estimating the upper quartile of the population. +``` {r, echo = TRUE} +plot(quantile_sim ~ samp.size, data = df_vole) +``` + +I would choose 15 as my ideal sample size. On the plot, the variation in the simulated upper quantiles narrows towards the end of the graph after sample size 15. + + +###Question 3 +###Question 3a +##With the upper quartile simulations, calculate the SD for each sample size using dplyr +``` {r, echo = TRUE} +print( +df_vole_summary <- df_vole %>% + group_by(samp.size) %>% + summarize(sd_mean_sim = sd(quantile_sim))) +``` + +###Question 3b +##What does this value, the standard error of the upper quartile, mean? +The standard error is an estimate of the standard deviation of the upper quartiles over all of the observed data. + +###Question 3c +##What is the CI of the upper quartile with a sample size of 10. What does this mean? +``` {r, echo = TRUE} +std.error <- (9.716814)/sqrt(10) +(1.96*std.error) +``` +This means that in the sample size of 10, 95% of the time you take a sample of upper quartile range, it will fall in the values of (9.71+/-6.022) 95% of the time the number will overlap the true value. + +9.71 is the simulated std dev of the upper quartile for 10 permutations. + + +###Question 3d +##Extra Credit: Instead of having each sim calculate a upper quartile, and then sifting down to the SE of that upper quartile (or the CI), have each simulation calculate a CI. Then, for just a sample size of 10, how many CI’s contain the true value of 83? +Ran out of time for the extra credit!! + +###3e +##Extra extra credit: If you find this question by pulling from your forked repository, +1 \ No newline at end of file