DOC PREVIEW
UW-Madison STAT 333 - Bats and Birds Example

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Statistics 333 Bats and Birds Example Spring 2003Here we look at the second case study in Chapter 10, involving bats, birds, and energy expenditure. The variables aremass (measured in grams), type, which is one of bird, echolocating bat, and non-echolocating bat, and energy expenditure inflight (measured in Watts). The data is on page 270 of the textbook (and on the previous hand out).The first plot to examine is a scatterplot of energy versus mass, using different symbols for the different types. This Rcode does this.> nBats <- type == "nBat"> eBats <- type == "eBat"> birds <- type == "bird"> plot(mass, energy, type = "n")> points(mass[nBats], energy[nBats], pch = 2)> points(mass[eBats], energy[eBats], pch = 17)> points(mass[birds], energy[birds], pch = 1)0 200 400 600 8000 10 20 30 40massenergy●●●●●●●●●●●●Now use the log scale.> plot(log(mass), log(energy), type = "n")> points(log(mass[nBats]), log(energy[nBats]), pch = 2)> points(log(mass[eBats]), log(energy[eBats]), pch = 17)> points(log(mass[birds]), log(energy[birds]), pch = 1)Bret Larget March 12, 2003Statistics 333 Bats and Birds Example Spring 20032 3 4 5 60 1 2 3log(mass)log(energy)●●●●●●●●●●●●Next, fit a linear model for the log transformed variables and plot the residuals.> fit <- lm(log(energy) ~ log(mass) + type)> plot(fitted(fit), residuals(fit))> abline(h = 0)●●●●●●●●●●●●●●●●●●●●0 1 2 3 4−0.2 0.0 0.2fitted(fit)residuals(fit)Bret Larget March 12, 2003Statistics 333 Bats and Birds Example Spring 2003Compare the summary from R to that found in the textbook on page 273.> summary(fit)Call:lm(formula = log(energy) ~ log(mass) + type)Residuals:Min 1Q Median 3Q Max-0.23224 -0.12199 -0.03637 0.12574 0.34457Coefficients:Estimate Std. Error t value Pr(>|t|)(Intercept) -1.47410 0.23902 -6.167 1.35e-05 ***log(mass) 0.81496 0.04454 18.297 3.76e-12 ***typeeBat -0.02360 0.15760 -0.150 0.883typenBat -0.10226 0.11418 -0.896 0.384---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Residual standard error: 0.186 on 16 degrees of freedomMultiple R-Squared: 0.9815, Adjusted R-squared: 0.9781F-statistic: 283.6 on 3 and 16 DF, p-value: 4.464e-14Summary of fit from the textbook.Variable Coefficient SE t p-valueConstant −1.5764 0.2872 −5.4880 < 0.0001log(mass) 0.8150 0.0445 18.2966 < 0.0001bird 0.1023 0.1142 0.8956 0.3837ebat 0.0787 0.2027 0.3881 0.7030Consider, for example, the equation to predict log(energy) from log(mass) for birds. From R, the intercept is −1.4741. Inthe textbook, it is −1.5764 + 0.1023 = −1.4741. The numerical summaries differ because R and the textbook made differentchoice as to which two (of three) levels of the factor type should be represented with indicator variables, a variable that is 1when for a given level and 0 for all other levels. Notice that the fitted values are identical, but that the parameterization isdifferent.Hypothesis testsSuppose that we wanted to test the hypothesis that the intercept for the echolocating bats and the non-echolocating batswas the same. From the textbook output, the implied model islog(energy) = β0+ β1(log(mass)) + β2(bird) + β3(eBat)The intercept for non-echolocating bats is β0and for echolocating bats is β0+ β3. Thus the null hypothesis is H0: β3= 0and the alternative is Ha: β36= 0. The test statistic is computed for us, t = 0.3881 with a p-value of 0.7030. There is littleevidence that the intercepts differ for the two types of bats.But can we do the same thing in R? Here, because the parameters were selected differently, there is a different impliedmodel.log(energy) = β0+ β1(log(mass)) + β2(eBat) + β3(nBat)Now the intercepts are β0+ β2and β0+ β3. If these are equal, then β2= β3. But, unfortunately, we cannot read this directlyoff the output. One solution is to force R to pick different levels for the indicator variables so that this test would be basedon a single coefficient. But there is another way.Bret Larget March 12, 2003Statistics 333 Bats and Birds Example Spring 2003The test statistic for the null hypothesis H0: β2− β3= 0 is t = (ˆβ2−ˆβ3)/SE(ˆβ2−ˆβ3). The formula for SE(ˆβ2−ˆβ3)comes from the general formula for the SE of g = C0ˆβ0+ C1ˆβ1+ · · · + Cpˆβp, which isSE(g) =vuutpXi=0C2iVar(ˆβi) + 2CiCjp−1Xi=0pXj=i+1Cov(ˆβi,ˆβj)For out case, all of the Ciare 0 except C2= 1 and C3= −1, soSE(ˆβ2−ˆβ3) =q12Var(ˆβ2) + (−1)2Var(ˆβ3) + 2(1)(−1)Cov(ˆβ2,ˆβ3)In R, we can find the variance-covariance matrix using the function vcov.> vc <- vcov(fit)> vc(Intercept) log(mass) typeeBat typenBat(Intercept) 0.057128374 -0.010374091 -0.029752785 0.006169357log(mass) -0.010374091 0.001983939 0.005138789 -0.001730953typeeBat -0.029752785 0.005138789 0.024837918 -0.001601645typenBat 0.006169357 -0.001730953 -0.001601645 0.013037676> se <- sqrt(vc[3, 3] + vc[4, 4] - 2 * vc[3, 4])> se[1] 0.2026793> tstat <- ((coef(fit))[3] - (coef(fit))[4])/se> tstattypeeBat0.3881190Compare this to the figure above.Here is the fit that forces the variable choices we made.> fit2 <- lm(log(energy) ~ log(mass) + birds + eBats)> summary(fit2)Call:lm(formula = log(energy) ~ log(mass) + birds + eBats)Residuals:Min 1Q Median 3Q Max-0.23224 -0.12199 -0.03637 0.12574 0.34457Coefficients:Estimate Std. Error t value Pr(>|t|)(Intercept) -1.57636 0.28724 -5.488 4.96e-05 ***log(mass) 0.81496 0.04454 18.297 3.76e-12 ***birdsTRUE 0.10226 0.11418 0.896 0.384eBatsTRUE 0.07866 0.20268 0.388 0.703---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Residual standard error: 0.186 on 16 degrees of freedomMultiple R-Squared: 0.9815, Adjusted R-squared: 0.9781F-statistic: 283.6 on 3 and 16 DF, p-value: 4.464e-14Bret Larget March 12,


View Full Document

UW-Madison STAT 333 - Bats and Birds Example

Download Bats and Birds Example
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Bats and Birds Example and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Bats and Birds Example 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?