Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
remlapmot committed Oct 1, 2019
0 parents commit 5328182
Show file tree
Hide file tree
Showing 263 changed files with 36,824 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
Box.log
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md
62 changes: 62 additions & 0 deletions 11-why-model-r.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# (PART\*) R code{-}

# 11. Why model?{-}

## Program 11.1

- Sample averages by treatment level
- Data from Figures 11.1 and 11.2

```{r out.width="85%", fig.align='center'}
A <- c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0)
Y <- c(200, 150, 220, 110, 50, 180, 90, 170, 170, 30,
70, 110, 80, 50, 10, 20)
plot(A, Y)
summary(Y[A == 0])
summary(Y[A == 1])
A2 <- c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4)
Y2 <- c(110, 80, 50, 40, 170, 30, 70, 50, 110, 50, 180,
130, 200, 150, 220, 210)
plot(A2, Y2)
summary(Y2[A2 == 1])
summary(Y2[A2 == 2])
summary(Y2[A2 == 3])
summary(Y2[A2 == 4])
```


## Program 11.2

- 2-parameter linear model
- Data from Figures 11.3 and 11.1

```{r out.width="85%", fig.align='center'}
A3 <-
c(3, 11, 17, 23, 29, 37, 41, 53, 67, 79, 83, 97, 60, 71, 15, 45)
Y3 <-
c(21, 54, 33, 101, 85, 65, 157, 120, 111, 200, 140, 220, 230, 217,
11, 190)
plot(Y3 ~ A3)
summary(glm(Y3 ~ A3))
predict(glm(Y3 ~ A3), data.frame(A3 = 90))
summary(glm(Y ~ A))
```

## Program 11.3

- 3-parameter linear model
- Data from Figure 11.3

```{r}
Asq <- A3 * A3
mod3 <- glm(Y3 ~ A3 + Asq)
summary(mod3)
predict(mod3, data.frame(cbind(A3 = 90, Asq = 8100)))
```
Loading

0 comments on commit 5328182

Please sign in to comment.