-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysisBF1.txt
92 lines (81 loc) · 4.17 KB
/
analysisBF1.txt
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
## Analysis in R
When working with a dataset the first thing to do is get to know your data through numerical and graphical summaries. Numerical summaries typically consist of means, standard deviations, and sample sizes for each factor level. Graphical summaries most usually are boxplots or scatterplots with the means displayed. Instructions for how to create these plots in R are found at [R Instructions-\>Descriptive Summaries](DescribeData.html) section of the book.
You then create the model using the `aov()` function. To see results of the F-test you can feed your model into a `summary()` function.
```{r}
#| eval: false
#| echo: true
myaov <- aov(Y ~ X, data=YourDataSet)
summary(myaov)
```
- `myaov` is some name you come up with to store the results of the aov() model.
- `Y` must be a "numeric" vector of the quantitative response variable.
- `X` is a qualitative variable (should have class(X) equal to factor or character. If it does not, use `factor(X)` inside the `aov(Y ~ factor(X),...)` command.
- `YourDataSet` is the name of your data set.
**Example Code**
<a href="javascript:showhide('bff1')">
<div class="hoverchunk">
<span class="tooltipr">
df
<span class="tooltiprtext">A name you come up with for your dataset</span>
</span><span class="tooltipr">
<-
<span class="tooltiprtext">The assignment operator. The result to the right of it gets stored in an object specified on the left</span>
</span><span class="tooltipr">
read_csv(
<span class="tooltiprtext">a command from the tidyverse to read in csv files</span>
</span><span class="tooltipr">
"data/toothpaste_BF2.csv"
<span class="tooltiprtext">The path to the csv file containing the data</span>
</span><span class="tooltipr">
)
<span class="tooltiprtext">Functions always end with a closing parenthesis</span>
</span><br/><span class="tooltipr">
plaque_aov<span class="tooltiprtext">A name you come up with for your model</span>
</span><span class="tooltipr">
<-
<span class="tooltiprtext">The assignment operator. The result to the right of it gets stored in an object specified on the left</span>
</span><span class="tooltipr">
aov(
<span class="tooltiprtext">A function to define the model</span>
</span><span class="tooltipr">
Plaque
<span class="tooltiprtext">The response, or y, variable in the model. It is numeric.</span>
</span><span class="tooltipr">
~
<span class="tooltiprtext">The ~ is like an equal sign in the model. Items on the left of ~ represent y, on the right you define independent factors (i.e. x's).</span>
</span><span class="tooltipr">
Brush,
<span class="tooltiprtext">The independent variable containing the names for the 4 types of toothbrushes.</span>
</span><span class="tooltipr">
data = df
<span class="tooltiprtext">Tell the model to look in the dataset named "df" for Plaque and Brush variables</span>
</span><span class="tooltipr">
)
<span class="tooltiprtext">Functions always end with a closing parenthesis</span>
</span><br/><span class="tooltipr">
summary(
<span class="tooltiprtext">Give important information about an object. When called on an aov object the default is to print the ANOVA table</span>
</span><span class="tooltipr">
plaque_aov
<span class="tooltiprtext">
Whatever you named your ANOVA model in the previous line
</span></span>
<span class="tooltipr">
)
<span class="tooltiprtext">
Functions always end with a closing parenthesis
</span></span><br/><span class="tooltipr" style="float:right;">
Click to view output
<span class="tooltiprtext">Click to View Output.</span>
</span>
</div>
</a>
<div id="bff1" style="display:none;">
```{r message = FALSE}
df <- read_csv("data/toothpaste_BF2.csv")
plaque_aov <- aov(Plaque ~ Brush, data = df)
summary(plaque_aov)
```
</div>
We then interpret the results. Since the p-value is significant we may be able to the graphical summaries to understand which factor level effects are significant. We may also want to do some [pairwise tests of the means](pairwise.qmd) or [contrasts](contrasts.qmd).
Now that the model is created the assumption need to be checked. Code and explanation for assumption checking can be found at [R Instructions-\>Model Assumptions](assumptions.qmd) section of the book.