In: Statistics and Probability
~~~~~~~~~~~~TO BE COMPLETED USING RSTUDIO~~~~~~~~~~~~~~
~~~~~~~~~~~~(PLEASE display all RCode used)~~~~~~~~~~~~~~
Goodness of Fit
Microhabitat factors associated with forage and bed sites of barking deer in Hainan Island, China, were examined. The sample of 477 examined sites where the deer forage were categorized by habitat as follows:
Habitat | Woods | Cultivated grassplots | Deciduous forests | Other |
Deer forage sites | 15 | 16 | 50 | 386 |
In this region, woods make up 4.8% of the land, cultivated
grassplots make up 14.7%, and deciduous forests make up
39.6%.
Do these data provide convincing evidence that barking deer prefer
to forage in certain habitats over others? Answer this research
question by conducting a goodness of fit test at 0.01 significance
level. Follow the steps outlined in the assignment
instructions.
Create a vector of assumed probabilities and use it to obtain and display a vector of expected values, then check that the assumptions required for this test are satisfied.
Find the P-value of the statistic using the appropriate chi-squared distribution.
Plot the distribution, a vertical line at the value of the test statistic, and show the P-value in the plot.
Verify that your statistic and P-value are correct by using the chisq.test instruction (if less than 10^ (-10),
consider both as zero).
(h) Do these data provide evidence that barking deer prefer to forage in certain habitats over others? Explain.
THIS MUST ALL BE COMPLETED AND DISPLAYED USING R STUDIO
observed <- c(12,22,66,392)
p
<- c(.048,.147,.396,1-(.048+.147+.396))
expected <- sum(observed) * p
expected
y
<- (expected -observed)^2/ expected
TS <- sum(y)
TS
p_val <- 1-pchisq(TS,3)
p_val
chisq.test(observed,p=p)
running code
observed <- c(12,22,66,392) > > p <- c(.048,.147,.396,1-(.048+.147+.396)) > expected <- sum(observed) * p > expected [1] 23.616 72.324 194.832 201.228 > y <- (expected -observed)^2/ expected > y [1] 5.713561 35.016108 85.189724 180.859304 > TS <- sum(y) > sum(TS) [1] 306.7787 > p_val <- 1-pchisq(TS,3) > p_val [1] 0
chisq.test(observed,p=p) Chi-squared test for given probabilities data: observed X-squared = 306.78, df = 3, p-value < 2.2e-16
c)
(Ei) = n * pi
d)
All Expected value should be greater than 5, hence the the assumptions required for this test are satisfied.
e)
X2 = 340.37
where DF is the degrees of freedom, k is the number of levels of the categorical variable, n is the number of observations in the sample, Ei is the expected frequency count for level i, Oi is the observed frequency count for level i, and X2 is the chi-square test statistic.
The P-value is the probability that a chi-square statistic having 3 degrees of freedom is more extreme than 340.37.
We use the Chi-Square Distribution Calculator to find P(X2 > 340.37) = less than 0.001.
Interpret results. Since the P-value (almost 0) is less than the significance level (0.05), we cannot accept the null hypothesis.
h) We have sufficient evidence in the favor of the claim that Barking deer prefer to forage in certain habitats over others.