Skip to content

Commit

Permalink
Update lab10
Browse files Browse the repository at this point in the history
  • Loading branch information
jarad committed Nov 14, 2024
1 parent eb6b88e commit 20b8c7b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 46 deletions.
2 changes: 1 addition & 1 deletion courses/stat5870Eng/labs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ tagline: Statistical Methods for Research Workers
- [Lab07](lab07/lab07.html) - RMarkdown
- [Lab08](lab08/lab08.html) - Categorical Explanatory Variables
- [Lab09](lab09/lab09.html) - Multiple Regression in R
- [Lab10](lab10/lab10.html) - ANOVA and F-tests

=== updated through here ===

- [Lab10](lab10/lab10.html) - ANOVA and F-tests
- [Lab11](lab11/lab11.html) - Contrasts
- [Lab12](lab12/lab12.html) - Generalized linear mixed effect models

Expand Down
8 changes: 5 additions & 3 deletions courses/stat5870Eng/labs/lab09/lab09.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@


## install.packages("GGally") # ggpairs()
## install.packages("GGally") # resid_panel() and resid_xpanel()
## install.packages("ggResidpanel") # resid_panel() and resid_xpanel()

library("tidyverse"); theme_set(theme_bw())
library("GGally")
library("Sleuth3")
library("GGally")
library("ggResidpanel")

# My diagnostic plots
my_diag <- function(m) {
resid_panel(m,
plots = c("qq", # qqplot for normality
Expand All @@ -23,7 +25,7 @@ my_diag <- function(m) {
}

ggplot(case1001, aes(Height, Distance)) +
geom_point() + theme_bw()
geom_point()

# First create the variables yourself
case1001_tmp <- case1001 |>
Expand Down
10 changes: 5 additions & 5 deletions courses/stat5870Eng/labs/lab09/lab09.html

Large diffs are not rendered by default.

30 changes: 1 addition & 29 deletions courses/stat5870Eng/labs/lab10/lab10.R
Original file line number Diff line number Diff line change
@@ -1,82 +1,54 @@
## -----------------------------------------------------------------------------
library("tidyverse")
library("Sleuth3")


## -----------------------------------------------------------------------------
m <- lm(Lifetime ~ Diet, data = case0501)
anova(m)


## -----------------------------------------------------------------------------
summary(m)


## -----------------------------------------------------------------------------
m0 <- lm(Lifetime ~ 1, data = case0501) # 1 indicates intercept
anova(m0, m)






## -----------------------------------------------------------------------------
m <- lm(Speed ~ Starters + Track, data = ex0920)
anova(m)


## -----------------------------------------------------------------------------
m0 <- lm(Speed ~ 1, data = ex0920)
mS <- lm(Speed ~ Starters, data = ex0920)
mT <- lm(Speed ~ Track, data = ex0920)
mST <- lm(Speed ~ Starters + Track, data = ex0920)


## -----------------------------------------------------------------------------
anova(m0, mS ) # we are looking to add (S)tarters to the model
anova(mS, mST) # we are looking to add (T)rack to the model


## -----------------------------------------------------------------------------
anova(m0, mS, mST)


## -----------------------------------------------------------------------------
m <- lm(Speed ~ Track*Starters, data = Sleuth3::ex0920)
anova(m)






## -----------------------------------------------------------------------------
m <- lm(Speed ~ Track + Starters, data = Sleuth3::ex0920)
drop1(m, test="F")


## -----------------------------------------------------------------------------
mT <- lm(Speed ~ Track, data = Sleuth3::ex0920)
mS <- lm(Speed ~ Starters, data = Sleuth3::ex0920)
mST <- lm(Speed ~ Track + Starters, data = Sleuth3::ex0920)
anova(mS,mST) # Consider adding Track into the model that already has Starters
anova(mT,mST) # Consider adding Starters into the model that already has Track


## -----------------------------------------------------------------------------
m <- lm(Ingestion ~ Weight + Organic, data = Sleuth3::ex0921)
drop1(m, test='F')




## -----------------------------------------------------------------------------
m <- lm(Ingestion ~ Weight * Organic, data = Sleuth3::ex0921)
drop1(m, test = 'F')


## -----------------------------------------------------------------------------
m0 <- lm(Ingestion ~ Weight + Organic, data = Sleuth3::ex0921)
anova(m0,m)

anova(m0, m)
5 changes: 3 additions & 2 deletions courses/stat5870Eng/labs/lab10/lab10.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ it will only attempt to drop the interaction.
m <- lm(Ingestion ~ Weight * Organic, data = Sleuth3::ex0921)
drop1(m, test = 'F')
```

It is not obvious from this output that you are comparing the model that
contains the main effects with the model that additional adds the interaction.
contains the main effects with the model that additionally adds the interaction.
You can check this with the `anova` function.

```{r}
m0 <- lm(Ingestion ~ Weight + Organic, data = Sleuth3::ex0921)
anova(m0,m)
anova(m0, m)
```

Notice that the statistics are all the same as the `drop1` results.
Expand Down
12 changes: 6 additions & 6 deletions courses/stat5870Eng/labs/lab10/lab10.html

Large diffs are not rendered by default.

0 comments on commit 20b8c7b

Please sign in to comment.