class: center, middle, inverse, title-slide # Statistal Inference ## RSS Module 3 Exam Paper 2011 --- <style type="text/css"> pre { background: #ADD8E6; max-width: 100%; overflow-x: scroll; } </style> ### Fertilizers Ten plants of a certain type, grown under standard conditions and treated with a new brand of fertiliser, attain the following heights (in cm). <pre><code> 25 28 24 23 27 30 24 21 28 30 </code></pre> * The sample mean is 26.0 and the sample variance is 9.33. * From extensive previous experiments, it is known that plants of the same type, grown under similar conditions but treated with a standard fertiliser, attain a mean height of 25.0 cm. --- ### Inputing Data into R environment ```r Heights <- c(25,28,24,23,27,30,24,21,28,30) ``` ```r mean(Heights) ``` ``` ## [1] 26 ``` ```r var(Heights) ``` ``` ## [1] 9.333333 ``` ```r sd(Heights) ``` ``` ## [1] 3.05505 ``` --- ### Exercises ***Questions on the RSS Exam Paper*** (i) Write down a statistical model for the distribution of plant heights in the population from which the sample is assumed to be drawn, including the definition of any unknown parameters. (ii) Obtain a 99% confidence interval for the population mean height of plants treated with the new fertiliser. (iii) Carefully specifying your hypotheses, conduct a test at the 10% significance level to decide whether there is evidence to suggest that the new fertiliser produces plants of greater mean height than the standard fertiliser. State your conclusions. (iv) Provide a 95% confidence interval for the population variance of the heights of plants treated with the new brand of fertiliser. --- ### 99% Confidence Interval We will use `\(\mu=25\)` here ```r t.test(Heights,mu=25,alpha=0.01) ``` ``` ## ## One Sample t-test ## ## data: Heights ## t = 1.0351, df = 9, p-value = 0.3276 ## alternative hypothesis: true mean is not equal to 25 ## 95 percent confidence interval: ## 23.81455 28.18545 ## sample estimates: ## mean of x ## 26 ``` The Confidence interval is (23.8,28.2) --- ### Using <tt> tidy() </tt> The <tt>tidy()</tt> function from the {broom} R package ```r library(broom) t.test(Heights,mu=25,alpha=0.01) %>% tidy() ``` ``` ## # A tibble: 1 x 8 ## estimate statistic p.value parameter conf.low conf.high method alternative ## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> ## 1 26 1.04 0.328 9 23.8 28.2 One Sampl~ two.sided ``` --- ### Hypothesis Test ```r t.test(Heights,mu=25, alpha=0.10, alternative="two.sided") ``` ``` ## ## One Sample t-test ## ## data: Heights ## t = 1.0351, df = 9, p-value = 0.3276 ## alternative hypothesis: true mean is not equal to 25 ## 95 percent confidence interval: ## 23.81455 28.18545 ## sample estimates: ## mean of x ## 26 ``` --- ```r t.test(Heights,mu=25, alpha=0.10, alternative="greater") ``` ``` ## ## One Sample t-test ## ## data: Heights ## t = 1.0351, df = 9, p-value = 0.1638 ## alternative hypothesis: true mean is greater than 25 ## 95 percent confidence interval: ## 24.22904 Inf ## sample estimates: ## mean of x ## 26 ``` --- ```r library(broom) t.test(Heights,mu=25,alpha=0.10,alterative="greater") %>% tidy() ``` ``` ## # A tibble: 1 x 8 ## estimate statistic p.value parameter conf.low conf.high method alternative ## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <chr> ## 1 26 1.04 0.328 9 23.8 28.2 One Sampl~ two.sided ``` --- ### <tt>Desctools::VarCI()</tt> #### Confidence Intervals for the Variance Calculates confidence intervals for the variance. Available approachs are the classical one using the ChiSquare distribution, a more robust version proposed by Bonett and the bootstrap options available in the package boot. #### Usage <pre><code>VarCI(x, method = c("classic", "bonett", "norm", "basic", "stud", "perc", "bca"), conf.level = 0.95, sides = c("two.sided", "left", "right"), na.rm = FALSE, R = 999) </code></pre> --- #### 95% Confidence Interval for Variance using standard method ```r library(DescTools) VarCI(Heights) ``` ``` ## var lwr.ci upr.ci ## 9.333333 4.415761 31.106624 ``` #### 99% Confidence Interval for Variance using "bonett" method ```r library(DescTools) VarCI(Heights, method="bonett", conf.level = 0.95) ``` ``` ## var lwr.ci upr.ci ## 9.333333 4.913021 27.428935 ``` --- ---