Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Take the homework assignment from last chapter and reformat it as an .rmd document (this means convert all the commentary to text, using appropriate

1) Take the homework assignment from last chapter and reformat it as an .rmd document (this means convert all the commentary to text, using appropriate headings; code comments can be left as comments). Choose one graph and hide the code that produces it (only for this assignment!), and use inline code to show results from some model or calculation.

R Code:

## Exercises

##1)## The built in data set `trees` has data for diameter, height, and timber volume for 31 trees. How well does the volume of a cone (0.333 x height x radius^2^ x pi) predict the timber volume (fit a regression between the measured and calculated volume). Note that volume is in cubic feet, height is in feet, and diameter is in inches (divide by 12 for feet). How does this differ from a model of measured volume as a function of height and diameter squared (which is mathematically incorrect)?

*Note on units* The variable named "Girth" is actually diameter according to the help file for the data set. See `? trees`.

data(trees)

summary(trees)

trees$cone.vol<-pi*0.333*trees$Height*(trees$Girth/2/12)^2

m3<-lm(Volume~cone.vol,data=trees)

summary(m3)

plot(Volume~cone.vol,data=trees)

abline(m3)

summary(lm(Volume ~ I(pi/3*trees$Height*(trees$Girth/24)^2), data = trees))

par(mfrow=c(1,2))

plot(m3,which=1:2)

m3.2<-lm(Volume~I(Height*Girth^2),data=trees)

summary(m3.2)

trees$Diam2<-with(trees,Girth*(Height/(Height-4.5))) # estimate ground-level diameter

summary(lm(Volume~I(Height/3*(Diam2/24)^2*pi),data=trees))

##2)## For the `beans` data test whether shoot biomass alters the relationship between root biomass and root length we explored in exercise 1 of Chapter 11.

beans<-read.csv("../Data/BeansData.csv",comm="#",header=TRUE)

for(i in c(2,4)) beans[,i]<-factor(beans[,i])

m4<-lm(rt.len~RtDM*ShtDM,data=beans)

summary(m4)

par(mfrow=c(1,2))

plot(m4,which=1:2,asp=1)

par(mfrow=c(1,2))

plot(rt.len~RtDM,data=beans);abline(lm(rt.len~RtDM,data=beans),col="red")

plot(rt.len~ShtDM,data=beans);abline(lm(rt.len~ShtDM,data=beans),col="red")

RDM<-seq(min(beans$RtDM,na.rm=T),max(beans$RtDM,na.rm=T),length.out=15)

SDM<-seq(min(beans$ShtDM,na.rm=T),max(beans$ShtDM,na.rm=T),length.out=15)

temp=expand.grid(list(RDM,SDM))

names(temp)=c("RDM","SDM")

params=summary(m4)$coeff[,1]

temp$RL=with(temp,params[1]+RDM*params[2]+SDM*params[3]+RDM*SDM*params[4])

require(lattice)

wireframe(RL~RDM*SDM,data=temp)

cloud(rt.len~RtDM*ShtDM,data=beans)

##3)## In exercise 3 and 4 of Chapter 12 we began looking at the "electric bill" data. Here is an ANCOVA problem. In April of 2008 (month 57 of occupancy) we added insulation to the roof of the house. How did this affect the relationship between daily energy use and average tempareature? Add a factor for with and without insulation, and add this factor to the quadratic model. How does this affect the fit of the model (consider residual distributions and *R*^2^)

elec <- read.delim("../Data/electric bill.txt")

elec$insul<-rep(0,nrow(elec))

elec$insul[57:nrow(elec)]<-1 # create a boolean for insulation

m3<-lm(kWhd.1~avgT+I(avgT^2)+insul, data=elec); summary(m3)

m2<-lm(kWhd.1~avgT+I(avgT^2), data=elec); summary(m2)

op<-par(mfrow=c(2,2),mar=c(4,4,2,0.5))

plot(m2,which=1:2)

plot(m3,which=1:2)

par(op)

##4)## Does the effect of adding insulation alter the coefficients of the relationship between temperature and daily electric consumption? (Do the `avgT` and `I(avgT^2)` terms interact with the insulation factor?)

m4<-lm(kWhd.1~avgT+I(avgT^2)+insul+insul:avgT+insul:I(avgT^2), data=elec); summary(m4)

m5<-lm(kWhd.1~avgT+insul+insul:avgT, data=elec); summary(m5)

m5<-lm(kWhd.1~avgT+insul, data=elec); summary(m5)

op<-par(mfrow=c(2,2),mar=c(4,4,2,0.5))

plot(m3,which=1:2)

plot(m5,which=1:2)

par(op)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What argument did the Supreme Court make?

Answered: 1 week ago

Question

highlight how to collect and record interview and diary based data;

Answered: 1 week ago