Description Usage Format Source See Also Examples
The data are the average values of brain weight, body weight, gestation lengths (length of pregnancy) and litter size for 96 species of mammals.
1 |
A data frame with 96 observations on the following 5 variables.
species
average brain weight (in grams)
average body weight (in kilograms)
gestation period (in days)
average litter size
Ramsey, F.L. and Schafer, D.W. (2013). The Statistical Sleuth: A Course in Methods of Data Analysis (3rd ed), Cengage Learning.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | str(case0902)
attach(case0902)
## EXPLORATION
myMatrix <- cbind(Brain, Body, Litter, Gestation)
if(require(car)){ # Use the car library
scatterplotMatrix(myMatrix, # Matrix of scatterplots
smooth=FALSE, # Omit scatterplot smoother on plots
diagonal="histogram") # Draw histograms on diagonals
}
myLm <- lm(Brain ~ Body + Litter + Gestation)
plot(myLm, which=1)
logBrain <- log(Brain)
logBody <- log(Body)
logGestation <- log(Gestation)
myMatrix2 <- cbind(logBrain,logBody,Litter, logGestation)
if(require(car)){ # Use the car library
scatterplotMatrix(myMatrix2, smooth=FALSE, diagonal="histogram")
}
myLm2 <- lm(logBrain ~ logBody + Litter + logGestation)
plot(myLm2,which=1) # Residual plot.
if(require(car)){ # Use the car library
crPlots(myLm2) # Partial residual plots (Sleuth Ch.11)
}
plot(logBrain ~ logBody)
identify(logBrain ~ logBody,labels=Species) # Identify points on scatterplot
# Place the cursor over a point of interest, then left-click.
# Continue with other points if desired. When finished, pres Esc.
## INFERENCE
summary(myLm2)
confint(myLm2)
# DISPLAYS FOR PRESENTATION
myLm3 <- lm(logBrain ~ logBody + logGestation)
beta <- myLm3$coef
logBrainAdjusted <- logBrain - beta[2]*logBody
y <- exp(logBrainAdjusted)
ymod <- 100*y/median(y)
plot(ymod ~ Gestation, log="xy",
xlab="Average Gestation Length (Days); Log Scale",
ylab="Brain Weight Adjusted for Body Weight, as a Percentage of the Median",
main="Brain Weight Adjusted for Body Weight, Versus Gestation Length, for 96 Mammal Species",
pch=21,bg="green",cex=1.3)
identify(ymod ~ Gestation,labels=Species, cex=.7) # Identify points, as desired
# Press Esc to complete identify.
abline(h=100,lty=2) # Draw horizontal line at 100%
myLm4 <- lm(logBrain ~ logBody + Litter)
beta <- myLm4$coef
logBrainAdjusted <- logBrain - beta[2]*logBody
y2 <- exp(logBrainAdjusted)
y2mod <- 100*y2/median(y2)
plot(y2mod ~ Litter, log="y", xlab="Average Litter Size",
ylab="Brain Weight Adjusted for Body Weight, as a Percentage of the Median",
main="Brain Weight Adjusted for Body Weight, Versus Litter Size, for 96 Mammal Species",
pch=21,bg="green",cex=1.3)
identify(y2mod ~ Litter,labels=Species, cex=.7)
abline(h=100,lty=2)
detach(case0902)
|
'data.frame': 96 obs. of 5 variables:
$ Species : Factor w/ 96 levels "Aardvark","Acouchis",..: 1 2 3 4 5 6 7 8 9 10 ...
$ Brain : num 9.6 9.9 4480 20.3 219 53 210 124 28.5 500 ...
$ Body : num 2.2 0.78 2800 2.8 89 6 66 16 3.2 250 ...
$ Gestation: int 31 98 655 104 218 60 158 183 65 240 ...
$ Litter : num 5 1.2 1 1.3 1 2.2 1.2 1.1 4 1.8 ...
Loading required package: car
integer(0)
Call:
lm(formula = logBrain ~ logBody + Litter + logGestation)
Residuals:
Min 1Q Median 3Q Max
-0.93895 -0.27922 -0.00929 0.28646 1.59743
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.82338 0.66206 1.244 0.21678
logBody 0.57455 0.03264 17.601 < 2e-16 ***
Litter -0.11038 0.04227 -2.611 0.01053 *
logGestation 0.43964 0.13698 3.210 0.00183 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.4756 on 92 degrees of freedom
Multiple R-squared: 0.9535, Adjusted R-squared: 0.952
F-statistic: 629.4 on 3 and 92 DF, p-value: < 2.2e-16
2.5 % 97.5 %
(Intercept) -0.4915254 2.13829063
logBody 0.5097143 0.63937813
Litter -0.1943220 -0.02643223
logGestation 0.1675856 0.71169994
integer(0)
integer(0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.