vignettes/session_lecture.Rmd
session_lecture.Rmd
For more detail: Vittinghoff section 4.2
\[ E[y|x] = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + ... + \beta_p x_p \]
\(y_i = E[y_i|x_i] + \epsilon_i\)
\(y_i = \beta_0 + \beta_1 x_{1i} + \beta_2 x_{2i} + ... + \beta_p x_{pi} + \epsilon_i\)
Assumption: \(\epsilon_i \stackrel{iid}{\sim} N(0, \sigma_\epsilon^2)\)
* STATA and R code dummy variables automatically, behind-the-scenes
Source of Variation | Sum Sq | Deg Fr | Mean Sq | F |
---|---|---|---|---|
Model | MSS | k | MSS/k | (MSS/k)/MSE |
Residual | RSS | n-(k-1) | RSS/(n-k-1) | |
Total | TSS | n-1 |
aov()
,
lm()
, glm()
, and coxph()
all
accept the “model formula” interface.response variable ~ explanatory variables
y ~ x
Additional explanatory variables would be added as follows:
y ~ x + z
Note that “+” does not have its usual meaning, which would be achieved by:
y ~ I(x + z)
lm( y ~ u + v)
u
and v
factors:
ANOVAu
and v
numeric: multiple
regression
one factor, one numeric: ANCOVA
symbol | example | meaning |
---|---|---|
+ | + x | include this variable |
- | - x | delete this variable |
: | x : z | include the interaction |
* | x * z | include these variables and their interactions |
/ | x / z | nesting: include z nested within x |
| | x | z | conditioning: include x given z |
^ | (u + v + w)^3 | include these variables and |
all interactions up to three way | ||
1 | -1 | intercept: delete the intercept |