Question (2) [5 marks] (Use R) Suppose you have a company producing cupcakes. Each cupcake is supposed to contain 10 grams of sugar. The cupcakes are produced by a machine that adds the sugar in a bowl before mixing everything. You believe the machine does not add 10 grams of sugar for each cupcake. If your assumption is true, the machine needs to be fixed. You stored the level of sugar of thirty cupcakes. Note: You can create a randomized vector with the function rnorm(). This function generates normally distributed values.
The basic syntax is: rnorm(n, mean, sd) arguments - n: Number of observations to generate - mean: The mean of the distribution. Optional (you can put what you want) - sd: The standard deviation of the distribution.
Optional Note: Why we are using set.seed?. Set the seed of R's random number generator, which is useful for creating simulations or random objects that can be reproduced. The random numbers are the same, and they would continue to be the same no matter how far out in the sequence we went.
a) [1 mark] Generate 30 observations from a Normal distribution with a mean of 9 and a standard deviation of 0.02. Set the seed to 123. Note: Show the R code that you used to generate the dataset and only the first 6 observations from the dataset (output).
b) [1 mark] State the hypothesis to check whether the level of sugar is different than the recipe (You can use either symbols or words).
c) [1 mark] Use a suitable test using R to check your hypothesis in (b), use a significance level (α) of 0.05. Note: Show the R code and the result/output of the hypothesis test.
d) [2 marks] Interpret your finding in (c). Note: State the degree of freedom (0.5 mark), interpret the hypothesis you are testing (interpret statistically and relating to the topic of interest) (1 mark) and interpret the confidence interval (0.5 mark). Note: Interpret the hypothesis statistically means: is it statistically significant or not?
Que.a
> set.seed(123)
> x=rnorm(30,9,0.02)
> head(x)
[1] 8.988790 8.995396 9.031174 9.001410 9.002586 9.034301
Que.b
Hypothesis:
Que.c
t.test(x,mu=10)
One Sample t-test
data: x
t = -279.42, df = 29, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 10
95 percent confidence interval:
8.991731 9.006384
sample estimates:
mean of x
8.999058
Que.d
Test statistic, t = -279.42
Degrees of freedom = 29
p value < 2.2e-16
Since p-value is less than 0.05, we reject null hypothesis and conclude that mean sugar content in cupcake is significantly different than 10.
Get Answers For Free
Most questions answered within 1 hours.