Skip to content

Commit

Permalink
work on Ch11
Browse files Browse the repository at this point in the history
  • Loading branch information
friendly committed Dec 20, 2024
1 parent 130036a commit 6ba1bf8
Show file tree
Hide file tree
Showing 44 changed files with 1,993 additions and 1,430 deletions.
846 changes: 846 additions & 0 deletions 01-intro.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions 10-mlm-review.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@ homogeneity of the variances and covariance matrices $\mathbf{S}_i$, I show only
#| out-width: "90%"
#| fig-cap: Bivariate data ellipses for pairs of the three responses, showing the means, correlations and variances for the three groups.
colors <- scales::hue_pal()(3) |> rev() # match color use in ggplot
covEllipses(cbind(caring, play, emotion) ~ group, data=Parenting,
covEllipses(cbind(caring, play, emotion) ~ group,
data=Parenting,
variables = 1:3,
fill = TRUE, fill.alpha = 0.2,
pooled = FALSE,
Expand Down Expand Up @@ -1090,7 +1091,7 @@ or, expressed in terms of the variables,
\begin{bmatrix} \beta_{0,\text{anx}} \\ \beta_{0,\text{dep}} \end{bmatrix} +
\begin{bmatrix} \beta_{1,\text{anx}} \\ \beta_{1,\text{dep}} \end{bmatrix} \text{grade} +
\begin{bmatrix} \beta_{2,\text{anx}} \\ \beta_{2,\text{dep}} \end{bmatrix} \text{grade}^2 \\
& + \cdots
& + \cdots +
\begin{bmatrix} \beta_{5,\text{anx}} \\ \beta_{5,\text{dep}} \end{bmatrix} \text{grade}^5
\end{eqnarray*} {#eq-AH-mod2}
Expand Down
45 changes: 39 additions & 6 deletions 11-mlm-viz.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ knitr::include_graphics("images/dogfood-quartet.png")



* In data space, each group is summarized by its **data ellipse**, representing the means and covariances.
* In data space (a), each group is summarized by its **data ellipse** (b), representing the means and covariances.

* Variation against the hypothesis of equal means can be seen by the $\mathbf{H}$ ellipse in the **HE plot**, representing the data ellipse of the fitted values. Error variance is shown in the $\mathbf{E}$ ellipse,
* Variation against the hypothesis of equal means can be seen by the $\mathbf{H}$ ellipse in the **HE plot** (c), representing the data ellipse of the fitted values. Error variance is shown in the $\mathbf{E}$ ellipse,
representing the pooled within-group covariance matrix, $\mathbf{S}_p$ and the data ellipse of the residuals from the model.
For the dogfood data, the group means have a negative relation: longer time to start eating is associated with a smaller amount eaten.

* The MANOVA (or Hotelling's $T^2$) is formally equivalent to a **discriminant analysis**, predicting
group membership from the response variables which can be seen in data space. (The main difference is
emphasis and goals: MANOVA seeks to test differences among group means, while discriminant analysis aims
at classification of the observations into groups.)

* This effectively projects the $p$-dimensional
space of the predictors into the smaller **canonical space** that shows the greatest differences among
the groups.
space of the predictors into the smaller **canonical space** (d) that shows the greatest differences among
the groups. As in a biplot, vectors show the relations of the response variables with the canonical dimensions.

<!--
```{r}
Expand Down Expand Up @@ -89,7 +90,14 @@ knitr::include_graphics("images/arcmanov.png")


For more complex models such as MANOVA with multiple factors or multivariate multivariate regression,
there is one $\mathbf{H}$ ellipse for each term in the model. ...
there is one sum of squares and products matrix (SSP), and therefore one
$\mathbf{H}$ ellipse for each term in the model. For example, in a two-way MANOVA design with the model
formula `(y1, y2) ~ A + B + A*B` and equal sample sizes in the groups, the total sum of squares accounted for by the model is
\begin{align*}
\mathbf{SSP}_{\text{Model}} & = \mathbf{SSP}_{A} + \mathbf{SSP}_{B} + \mathbf{SSP}_{AB} \\
& = \mathbf{H}_A + \mathbf{H}_B + \mathbf{H}_{AB} \period
\end{align*}


## HE plot construction

Expand All @@ -116,9 +124,14 @@ puts this on the same scale as the \E ellipse.
I refer to this as _effect size scaling_, because it is similar to an effect size index used in
univariate models, e.g., $ES = (\bar{y}_1 - \bar{y}_2) / s_e$ in a two-group, univariate design.

This is illustrated in ...
### Example: Iris data

**TODO**: Introduce the iris data earlier. Where???

@fig-iris-HE1 shows two views of the relationship between sepal length and sepal width for the iris data. ...
<!--
```{r}
#| eval: false
op <- par(mar = c(4, 4, 1, 1) + .5,
mfrow = c(1, 2))
col <-c("blue", "darkgreen", "brown")
Expand All @@ -143,6 +156,15 @@ par(op)
```
-->

```{r}
#| label: fig-iris-HE1
#| out-width: "100%"
#| fig-cap: "Iris data: Data ellipses and HE plot"
knitr::include_graphics("images/iris-HE1.png")
```


### Significance scaling

The geometry of ellipsoids and multivariate tests allow us to go further with another re-scaling of the $\mat{H}$ ellipsoid
that gives a _visual test of significance_ for any term in a MLM.
Expand All @@ -164,6 +186,17 @@ where $\text{df}_1 = \max(p, \text{df}_h)$ and $\text{df}_2 = \text{df}_h + \tex
For these data, the HE plot using
significance scaling is shown in the right panel of \figref{fig:heplot-iris1}.

```{r}
#| label: fig-iris-HE2
#| out-width: "100%"
#| fig-cap: "HE plots for sepal width and sepal length in the iris dataset. Left: effect scaling of the $\\mathbf{H}$ magtrix; right: significance scaling"
knitr::include_graphics("images/iris-HE2.png")
```


### Contrasts

### HE plot matrices

## Canonical discriminant analysis {#sec-candisc}

Expand Down
4 changes: 4 additions & 0 deletions R/iris/iris-HE.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ heplot(iris.mod, hypotheses=hyp, fill=TRUE,
# vary label position and fill.alpha
heplot(iris.mod, hypotheses=hyp, fill=TRUE, fill.alpha=c(0.3,0.1), col=c("red", "blue"),
lty=c(0,0,1,1), label.pos=0:3)

pairs(iris.mod,
fill=TRUE, fill.alpha=c(0.3,0.1)
)
38 changes: 6 additions & 32 deletions bib/pkgs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ @Manual{R-broom
}

@Manual{R-candisc,
title = {candisc: Visualizing Generalized Canonical Discriminant and Canonical Correlation Analysis},
title = {candisc: Visualizing Generalized Canonical Discriminant and Canonical
Correlation Analysis},
author = {Michael Friendly and John Fox},
year = {2024},
note = {R package version 0.9.0},
Expand All @@ -44,7 +45,7 @@ @Manual{R-candisc
@Manual{R-car,
title = {car: Companion to Applied Regression},
author = {John Fox and Sanford Weisberg and Brad Price},
year = {2024},
year = {2023},
note = {R package version 3.1-3},
url = {https://r-forge.r-project.org/projects/car/},
}
Expand Down Expand Up @@ -89,14 +90,6 @@ @Manual{R-corrplot
url = {https://github.com/taiyun/corrplot},
}

@Manual{R-datasauRus,
title = {datasauRus: Datasets from the Datasaurus Dozen},
author = {Colin Gillespie and Steph Locke and Rhian Davies and Lucy {D'Agostino McGowan}},
year = {2024},
note = {R package version 0.1.8},
url = {https://github.com/jumpingrivers/datasauRus},
}

@Manual{R-datawizard,
title = {datawizard: Easy Data Wrangling and Statistical Transformations},
author = {Indrajeet Patil and Etienne Bacher and Dominique Makowski and Daniel Lüdecke and Mattan S. Ben-Shachar and Brenton M. Wiernik},
Expand Down Expand Up @@ -316,14 +309,6 @@ @Manual{R-knitr
url = {https://yihui.org/knitr/},
}

@Manual{R-langevitour,
title = {langevitour: Langevin Tour},
author = {Paul Harrison},
year = {2024},
note = {R package version 0.7},
url = {https://logarithmic.net/langevitour/},
}

@Manual{R-lattice,
title = {lattice: Trellis Graphics for R},
author = {Deepayan Sarkar},
Expand Down Expand Up @@ -359,9 +344,9 @@ @Manual{R-marginaleffects

@Manual{R-MASS,
title = {MASS: Support Functions and Datasets for Venables and Ripley's MASS},
author = {Brian Ripley and Bill Venables},
author = {Brian Ripley},
year = {2024},
note = {R package version 7.3-61},
note = {R package version 7.3-60.0.1},
url = {http://www.stats.ox.ac.uk/pub/MASS4/},
}

Expand Down Expand Up @@ -638,7 +623,7 @@ @Book{car2019
year = {2019},
publisher = {Sage},
address = {Thousand Oaks {CA}},
url = {https://www.john-fox.ca/Companion/},
url = {https://socialsciences.mcmaster.ca/jfox/Books/Companion/},
}

@Misc{correlationPackage,
Expand Down Expand Up @@ -865,17 +850,6 @@ @InCollection{knitr2014
note = {ISBN 978-1466561595},
}

@Article{langevitour2023,
title = {langevitour: Smooth Interactive Touring of High Dimensions, Demonstrated with scRNA-Seq Data},
author = {Paul Harrison},
journal = {The R Journal},
year = {2023},
volume = {15},
number = {2},
pages = {206-219},
doi = {10.32614/RJ-2023-046},
}

@Book{lattice2008,
title = {Lattice: Multivariate Data Visualization with R},
author = {Deepayan Sarkar},
Expand Down
Loading

0 comments on commit 6ba1bf8

Please sign in to comment.