-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathabd17-20.Rmd
More file actions
93 lines (88 loc) · 3 KB
/
abd17-20.Rmd
File metadata and controls
93 lines (88 loc) · 3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
title: "Analysis of Biological Data Chapter 17 Assignment Problems 20-21"
author: "your name"
date: "`r Sys.Date()`"
output:
html_document:
highlight: pygments
toc: yes
major: regression modeling; ABD
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')
```
```{r input}
# What is between data <- .. and ') is exactly like an external .csv file
data <- textConnection('
species,mass,rate
alouatta palliata,4670,11.6
aotus trivirgatus,1020,2.6
arctocebus calabarensis,206,.7
callithrix jachus,190,.9
cebuella pygmaea,105,.6
cheirogaleus medius,300,1.1
euoticus elegantilus,261.5,1.2
galago crassicaudatus,1039,2.9
galago demidovii,61,.4
galago elegantulus,261.5,1.2
homo sapiens,70000,82.8,
lemur fulvus,2330,4.2
nycticebus coucang,1300,1.7
papio anubis,9500,16
perodicticus potto,1011,2.1
saguinus geoffroyi,225,1.3
saimiri sciureus,800,4.4
')
d <- csv.get(data)
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}
contents(d)
d # same as print(d)
# Function to form 2-letter versions of species names using
# first letter of each word
w <- function(x) {
x <- strsplit(as.character(x), split=' ')
sapply(x, function(y) paste(substring(y, 1, 1), collapse=''))
}
ggplot(d, aes(x=mass, y=rate, color=species)) + geom_point() +
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')
```
# Exponential Regression Fit
An equation of the form $R = \alpha M ^ \beta$, if errors are multiplicative on the original scale, can be fitted using linear regression after logging both sides of the model.
With R you can log while fitting, without creating new variables. A predicted value plot has the data superimposed, using the original scale for both variables.
```{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), 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.
```{r ci}
summary(f, mass=c(10,100))
```
The confidence interval gives an automatic hypothesis test.
# Model Diagnostics
Insert your code and interpretations here.
# Computing Environment
```{r rsession,echo=FALSE}
si <- sessionInfo(); si$loadedOnly <- NULL
print(si, locale=FALSE)
```
```{r cite,results='asis',echo=FALSE}
print(citation(), style='text')
```