-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quadro_7.4_p155.Rmd
50 lines (43 loc) · 1.12 KB
/
Quadro_7.4_p155.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
---
title: "Quadro 7.4"
author: "William"
date: "2 de setembro de 2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(datasets)
require(stats)
require(graphics)
data(InsectSprays);
boxplot(count ~ spray, data = InsectSprays, col = "lightgray",
xlab="Tipo do spray", ylab="Quantidade de insetos")
```
```{r}
# modelo linear
summary(lm(count ~ spray, data = InsectSprays))$coef
# explicitando o modelo
summary(lm(count ~
I(1 * (spray == 'B')) + I(1 * (spray == 'C')) +
I(1 * (spray == 'D')) + I(1 * (spray == 'E')) +
I(1 * (spray == 'F'))
, data = InsectSprays))$coef
```
```{r}
# e se incluirmos as 6 variáveis
summary(lm(count ~
I(1 * (spray == 'B')) + I(1 * (spray == 'C')) +
I(1 * (spray == 'D')) + I(1 * (spray == 'E')) +
I(1 * (spray == 'F')) + I(1 * (spray == 'A')), data =
InsectSprays))$coef
```
```{r}
# e se omitirmos o intercepto
summary(lm(count ~ spray - 1, data = InsectSprays))$coef
unique(ave(InsectSprays$count, InsectSprays$spray))
# reordenando os níveis
spray2 <- relevel(InsectSprays$spray, "C")
summary(lm(count ~ spray2, data = InsectSprays))$coef
```