Answer with R studio script please . Question: Here\'s the data: 5. For this exe
ID: 3199193 • Letter: A
Question
Answer with R studio script please.
Question:
Here's the data:
5. For this exercise, submit your R script file via canvas, but do not forget to answer the questions on paper as well A researcher is interested in analyzing 18 butterfly species/populations. For each butterfly population, we have an altitude of the population habitat and a population frequency of a candidate gene that is suspected to be responsible for butterfly adapta- tion to living at different altitudes. The data are in the file butterflydata.txt, which is posted on canvas together with the homework. The table contains two columns Altitude (measured in thousand of feet) and HkFrequency. We are interested in in vestigating a question of whether the butterfly habitat altitude is predictive of the candidate gene frequency. (a) Load the data into R and plot HkFrequency (y-axis) against Altitude (x-axis) and against 1/Altitude (x-axis) (b) Based on observed linearity in the scatter plots in part (a), choose your covariate to be either Altitude or 1/Altitude and fit a linear regression with HkFrequency as a response (c) Plot you regression residuals and comment on adequacy of linear mode fit. (d) How much variance in Hk gene frequency is explained by changes in butterfly (e) Using normal 95% confidence intervals, can you conclude with confidence that the (f) Does the change in altitude lead to scientifically interesting changes in Hk gene (g) Suppose population of butterflies moves an altitude of 1200 feet another habitat habitat altitude? slope of the regression is not zero? frequency? Explain your answer which is 2400 feet high. Using your linear regression results, predict the corre- sponding change in Hk gene frequency after the population adapts to the new environmentExplanation / Answer
Altitude<-c(0.50, 0.80, 0.57, 0.55, 0.38, 0.93, 0.48,
0.63, 1.5, 1.75, 2, 4.2, 2.5, 2, 6.5, 7.85, 8.95, 10.50)
HkFrequency<-c(98, 36, 72, 67, 82, 72, 65, 1, 40, 39,
9, 19, 42, 37, 16, 4, 1, 4)
table<-data.frame(Altitude,HkFrequency)
attach(table)
#a)
#we plot Altitude vs HkFrequency
plot(Altitude,HkFrequency)
#Then we plot 1/Altitude vs HkFrequency
plot(1/Altitude,HkFrequency)
#b)
#The second plot looks more linear so we choose our covariate to be 1/Altitude
x<-1/Altitude
#We perform the linear regression
model=lm(HkFrequency~x) ##lm(y~x)
#We report the results
summary(model)
#We draw the estimated line
abline(model,lty=1, col="red")
#c)
#now we plot the residuals
res<-resid(model)
plot(x, res,
ylab="Residuals", xlab="1/Altitude")
abline(0, 0, col="blue") # the horizon
#d)
#We compute the ANOVA
anova(model)
#Altitude explains 9588.4 of the total variance(9588.4+6569.3=16157.7)
#Which is 59.34% of the total variance (This also can be seen in the R squared in summary)
#e)
#Confidence Intervals
confint(model, level = .95)
#The 95 %confidence interval for the slope is (16.353300, 41.91352)
#So we can conclude ithe slope is not zero
#f)
#Then since the slope is not zero with 95% of confidence
#we can conclude that change in altitude lead to changes in Hk frequency
#g)
#the intercept is 10.683 and the slope is 29.133
#Thus HK=10.683+(29.133)*(1/Altitude)
b=model$coefficients[[1]] #intercept
m=model$coefficients[[2]] #slope
#Then when Altitude=1.2 (thousands of feet )
Hk1=b+m/1.2
#And when Altitude=2.4 (thousands of feet )
Hk2=b+m/2.4
#Then the change is -12.13892
Hk2-Hk1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.