Skip to content

Commit

Permalink
added journal references for data sources, improved graph cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Harrell committed May 16, 2015
1 parent de9a09e commit 260b597
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 42 deletions.
15 changes: 9 additions & 6 deletions abd17-1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ minor: ordinary least squares
---

# Data
The data are from Carré, J. M., and C. M McCormick. 2008. _Proceedings of the
Royal Society of London, Series B, Biological Sciences_ **275**:2651–2656.
```{r input}
require(rms)
knitrSet(lang='markdown')
Expand All @@ -19,12 +21,13 @@ face <- c(159,167,165,172,179,177,174,174,177,178,176,
penalty <- c(44,143,157,14,27,35,85,113,147,151,199,
106,120,123,80,253,123,110,161,195,295)/100
d <- data.frame(face, penalty)
d <- upData(d, labels=c(face = 'Face Width:Height Ratio',
penalty = 'Penalty Minutes'))
xl <- 'Face Width:Height Ratio'
yl <- 'Penalty Minutes'
d <- upData(d, labels=c(face = xl, penalty = yl))
```
```{r show}
d # same as print(d)
ggplot(d, aes(x=face, y=penalty)) + geom_point()
ggplot(d, aes(x=face, y=penalty)) + geom_point() + xlab(xl) + ylab(yl)
dd <- datadist(d); options(datadist='dd')
```
# Linear Regression Fit
Expand All @@ -42,7 +45,7 @@ seb <- sqrt(mse / sxx)
c(xbar=mean(x), ybar=mean(y), sxx=sxx, syy=syy, sxy=sxy, b=b, mse=mse, seb=seb)
tcrit <- qt(0.975, n - 2)
tcrit
f <- ols(penalty ~ face)
f <- ols(penalty ~ face, data=d)
f
anova(f)
```
Expand All @@ -53,12 +56,12 @@ r <- resid(f)
par(mfrow=c(1,2)) # 1x2 matrix of plots
plot(fitted(f), r); abline(h=0) # yhat vs. r
qqnorm(r) # linearity indicates normality
qqline(r)
qqline(as.numeric(r))
```

# Partial Effects of Predictors With Raw Data
```{r peffects}
ggplot(Predict(f, face=seq(1.59, 2.07, length=100))) +
ggplot(Predict(f, face=seq(1.59, 2.07, length=100)), ylab=yl) +
geom_point(aes(x=face, y=penalty), d)
```

Expand Down
27 changes: 15 additions & 12 deletions abd17-1.html

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions abd17-20.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ minor: ordinary least squares
---

# Data
The data are from Heusner, A. A. 1991. Size and power in mammals. _Journal of Experimental Biology_ **160**: 25-54.
```{r setup}
require(rms)
knitrSet(lang='markdown')
Expand Down Expand Up @@ -42,6 +43,8 @@ close(data)
d <- upData(d, labels=c(species = 'Species', mass='Mass',
rate = 'Basal metabolic rate'),
units=c(mass='g', rate='watts'))
xl <- label(d$mass, plot=TRUE, units=TRUE)
yl <- label(d$rate, plot=TRUE, units=TRUE)
```
Raw data are plotted using log10 scales for x and y.
```{r show,h=4}
Expand All @@ -55,8 +58,8 @@ w <- function(x) {
}
ggplot(d, aes(x=mass, y=rate, color=species)) + geom_point() +
geom_text(aes(label=w(species)), size=3, hjust=1.2) +
scale_x_log10() + scale_y_log10() +
geom_text(aes(label=w(species)), size=3, hjust=1.3) +
scale_x_log10() + scale_y_log10() + xlab(xl) + ylab(yl) +
guides(col=guide_legend(nrow=4, override.aes=list(size=1))) +
theme(legend.position='bottom', legend.text=element_text(size=4), legend.key.size=unit(2, 'mm'))
dd <- datadist(d); options(datadist='dd')
Expand All @@ -68,7 +71,7 @@ With R you can log while fitting, without creating new variables. A predicted v
```{r fit}
f <- ols(log10(rate) ~ log10(mass), data=d)
f
ggplot(Predict(f, mass=seq(50, 70000, by=50), fun=function(y) 10^y)) +
ggplot(Predict(f, mass=seq(50, 70000, by=50), fun=function(y) 10^y), ylab=yl) +
geom_point(aes(x=mass, y=rate), data=d)
```
The confidence interval for $\beta$ (slope of mass on the log10 scale) can be obtained from the confidence interval for a 10-fold change in mass.
Expand Down
17 changes: 10 additions & 7 deletions abd17-20.html

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions abd17-28.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ minor: ordinary least squares
---

# Data
The data are from Sherwood, C. C., _et al_. 2006. _Proceedings of the National Academy of Sciences (USA)_ **103**: 13606–13611.
```{r setup}
require(rms)
knitrSet(lang='markdown')
Expand Down Expand Up @@ -43,6 +44,8 @@ close(data)
d <- upData(d, labels=c(species = 'Species', mass='Brain Mass',
ratio = 'Glia-neuron Ratio'),
units=c(mass='g'))
xl <- label(d$mass, plot=TRUE, units=TRUE)
yl <- label(d$ratio)
```
Raw data are logging x then logging both x and y.
```{r show,h=4}
Expand All @@ -57,15 +60,15 @@ w <- function(x) {
}
ggplot(d, aes(x=mass, y=ratio, color=species)) + geom_point() +
geom_text(aes(label=w(species)), size=2, hjust=1.2) +
scale_x_log10(breaks=c(10,25,50,100,200,500,1000)) +
geom_text(aes(label=w(species)), size=2, hjust=1.3) +
scale_x_log10(breaks=c(10,25,50,100,200,500,1000)) + xlab(xl) + ylab(yl) +
guides(col=guide_legend(nrow=4, override.aes=list(size=1))) +
theme(legend.position='bottom', legend.text=element_text(size=4),
legend.key.size=unit(2, 'mm'))
ggplot(d, aes(x=mass, y=ratio, color=species)) + geom_point() +
geom_text(aes(label=w(species)), size=2, hjust=1.2) +
scale_x_log10(breaks=c(10,25,50,100,200,500,1000)) +
geom_text(aes(label=w(species)), size=2, hjust=1.3) +
scale_x_log10(breaks=c(10,25,50,100,200,500,1000)) + xlab(xl) + ylab(yl) +
scale_y_log10(breaks=c(.25,.5,.75,1,1.25,1.5,2)) +
theme(legend.position='none')
Expand All @@ -77,7 +80,7 @@ Note that it is unusual not to log a ratio, but the preliminary analysis in ABD
```{r fit}
f <- ols(ratio ~ log(mass), data=d, subset=species != 'homo sapiens')
f
ggplot(Predict(f, mass=seq(10, 1400, by=25))) +
ggplot(Predict(f, mass=seq(10, 1400, by=25)), ylab=yl) +
geom_point(aes(x=mass, y=ratio), data=d)
```

Expand Down
21 changes: 12 additions & 9 deletions abd17-28.html

Large diffs are not rendered by default.

0 comments on commit 260b597

Please sign in to comment.