-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDA-LogLinearModel.Rmd
More file actions
60 lines (52 loc) · 1.58 KB
/
CDA-LogLinearModel.Rmd
File metadata and controls
60 lines (52 loc) · 1.58 KB
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
---
title: "Loglinear Model Analysis"
author: "Riley Smith"
date: "`r format(Sys.Date(), '%d %B %Y')`"
---
```{r setup, echo=FALSE, message=FALSE, warning=FALSE, cache=FALSE}
source("../SETUP.R")
options(width = 70)
knitr::opts_chunk$set(
tidy = FALSE,
echo = TRUE,
cache = FALSE,
fig.keep = 'high',
fig.show = 'asis',
results = 'asis',
autodep = T,
Rplot = TRUE,
dev = 'pdf',
fig.path = 'graphics/reuters/rplot_',
fig.width = 7,
fig.asp = 1,
out.width = "\\linewidth"
)
library(foreign) ## read.spss() ##
library(car) ## recode() ##
```
`r tufte::margin_note("Data: \\textit{\\color{dkpatriarch}{\\texttt{data/reuters.sav}}}")`
$$ \log(\mu_{ij}) = \lambda + \lambda_{i}^{X} + \lambda_{j}^{Y} + \lambda_{ij}^{XY} $$
```{r}
dat <- R.rspss("data/reuters.sav", vlabs = F)
R.msmm(dat)
dat <- dat[, -3]
dat <- subset(dat, response < 2)
dat <- within(dat, {
ind.f <- factor(ind,
levels = unique(ind),
labels = c("Independent",
"Affililate"))
response.f <- factor(response,
levels = c(0, 1),
labels = c("Trump",
"Clinton"))
})
tbl <- table(dat$ind.f, dat$response.f)
dimnames(tbl) <- list(ind = levels(dat$ind.f),
response = levels(dat$response.f))
mosaicplot(tbl, type = "deviance", las = 2, color = pal_my.a75[c(5, 16)])
library(MASS)
logmodel <- loglm( ~ ind + response, digits = 4, data = tbl)
```
\newpage
# References`r R.cite_r("~/GitHub/auxDocs/REFs.bib", footnote = TRUE)`