In: Statistics and Probability
Please solve it by R
(1) Find the mean and variance of the variable of ’volume’ in ’lung’ dataset in package ’ISwR’.
(2) Check the normality of the variable of ’volume’ in ’lung’ dataset in package ’ISwR’ with significance level α = 0.1.
(3) Test if the mean of ’volume’ is less than 3.3 with significance level α = 0.05.
Please find attached R codes. Just copy the commands in R script and run the program by pressing Ctrl+R.
If using R studio then press Ctrl+Enter.
Codes also include installing ISwR package.
install.packages("ISwR") library("ISwR", lib.loc="~/R/win-library/3.5") data=lung data$volume #to find mean and variance of volume mean(data$volume) var(data$volume) #to check normality shapiro.test(data$volume) #to check if the mean is greater than 3.3 t.test(data$volume,mu=3.3,alternative = "less")
Part 1)
Mean of volume = 3.227778
Variance of volume = 0.2409477
Part 2)
Now to check the normality of the variable volume we use the Shapiro Wilk test of normality. It tests whether the sample is coming from the Normal population or not. Following is the output of R.
Shapiro-Wilk normality test
data: data$volume
W = 0.94197, p-value = 0.3131
The P-value for the test is 0.3131.
At the 0.1 level of significance, the p-value is much higher than the level of significance.
Hence we do not have enough evidence to reject the null hypothesis.
Variable volume is coming from the normal population at 0.1 level of significance.
Part 3)
Now to check if the mean of volume is less than 3.3 with the level of significance 0.05.
We use one-sample t-test to check the hypothesis we made.
For the one-sample t-test, we need the assumption of normality to be satisfied, which we have already checked in the above part of the solution.
Null hypothesis: mean=3.3
Versus
Alternative hypothesis: mean<3.3
Hence this is a one-sided one-sample t-test.
Using the direct command in R for the t-test.
In R command the argument mu is the hypothesized value of the parameter specified under the null hypothesis.
By default R tests for both-sided alternative hypothesis but, as we want to test for single-sided hence we use another argument as "less" according to our alternative hypothesis.
#If we have an alternative hypothesis of greater than kind then we can use "greater" as an argument.
Following is the output:
One Sample t-test
data: data$volume
t = -0.62423, df = 17, p-value = 0.2704
alternative hypothesis: true mean is less than 3.3
95 percent confidence interval:
-Inf 3.429046
sample estimates:
mean of x
3.227778
The P-value for the test is 0.2704.
As the P-value is much higher than level of significance, we do not have enough evidence to reject the null hypothesis.
Hence at 0.05 level of significance, we accept that mean of 'volume' is 3.3.
Hence at 0.05 level of significance, we can say that mean of 'volume' is not less than 3.3
I have tried to explain as much as possible. I hope you find the solution helpful. Please do not forget to rate the answer.
Feel free to ask any doubts regarding the solution.