-
Notifications
You must be signed in to change notification settings - Fork 23
/
abd18-11.Rmd
103 lines (99 loc) · 2.14 KB
/
abd18-11.Rmd
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
94
95
96
97
98
99
100
101
102
103
---
title: "Analysis of Biological Data Chapter 18 Assignment Problem 11"
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 Langford, D. J., _et al_. 2006. Science **312**: 1967--1970.
```{r setup}
require(rms)
knitrSet(lang='markdown')
```
```{r input}
# What is between data <- .. and ') is exactly like an external .csv file
data <- textConnection('
condition,stretching
companion,36.7
companion,81.1
companion,66.7
companion,66.7
companion,44.4
companion,54.4
companion,63.3
companion,62.2
companion,58.9
companion,50
companion,54.4
companion,57.8
companion not,56.7
companion not,51.1
companion not,50
companion not,51.1
companion not,44.4
companion not,2.2
companion not,41.1
companion not,33.3
companion not,25.6
companion not,22.2
companion not,14.4
companion not,3.3
companion not,64.4
isolated,46.7
isolated,38.9
isolated,65.6
isolated,35.6
isolated,32.2
isolated,30
isolated,41.1
isolated,63.3
isolated,0
isolated,53.3
isolated,22.2
isolated,48.9
isolated,5.6
isolated,14.4
isolated,46.7
isolated,45.6
isolated,42.2
')
d <- csv.get(data)
close(data)
yl <- 'Percent of Time Stretching'
d <- upData(d, labels=c(stretching = yl))
d
dd <- datadist(d); options(datadist='dd')
```
# Anova Model
```{r fit,h=1.5}
f <- ols(stretching ~ condition, data=d)
f
anova(f)
# Complication: had to reverse x and y in geom_point because ggplot(Predict())
# has already reversed them once
# Estimated group means are black dots, raw data blue dots
# Bars are 0.95 confidence intervals
ggplot(Predict(f)) + ylab(yl) + xlab(NULL) +
geom_point(aes(y=stretching, x=condition), col='blue', alpha=.3, data=d)
```
# Null Model
The `ols` function does not allow a null model. Use the builtin R `lm` function.
```{r nullfit}
fnull <- lm(stretching ~ 1, data=d)
# lm has a different way to print parameter estimates: summary()
summary(fnull)
anova(fnull)
```
# 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')
```