Update slides
This commit is contained in:
Binary file not shown.
@@ -173,7 +173,7 @@ xyplot(Reaction ~ Days | Subject,
|
||||
\begin{itemize}
|
||||
\item The random intercept model adds a random intercept for each subject
|
||||
\[
|
||||
y_{ij} = \beta_0 + \beta_1\,Days_{ij} + \upsilon_{0i} + \varepsilon_i
|
||||
y_{ij} = \beta_0 + \beta_1\,Days_{ij} + \upsilon_{0i} + \varepsilon_{ij}
|
||||
\]
|
||||
with $\upsilon_{0i} \overset{iid}{\sim} N(0, \sigma^2_{\upsilon})$,
|
||||
$\varepsilon_{ij} \overset{iid}{\sim} N(0, \sigma^2_\varepsilon)$
|
||||
@@ -455,7 +455,7 @@ with
|
||||
\end{column}
|
||||
\begin{column}{.4\textwidth}
|
||||
\[
|
||||
y_{ij} = \beta_0 + \beta_1 time + \upsilon_{0i} + \upsilon_{1i} time +
|
||||
y_{ij} = \beta_0 + \beta_1 t_{ij} + \upsilon_{0i} + \upsilon_{1i} t_{ij} +
|
||||
\varepsilon_{ij}
|
||||
\]
|
||||
with
|
||||
@@ -466,7 +466,8 @@ with
|
||||
\sigma^2_{\upsilon_0} & \sigma_{\upsilon_0 \upsilon_1} \\
|
||||
\sigma_{\upsilon_0 \upsilon_1} & \sigma^2_{\upsilon_1} \\
|
||||
\end{pmatrix} \right)\\
|
||||
\boldsymbol{\varepsilon}_i &\overset{iid}\sim N(\mathbf{0}, \, \sigma^2
|
||||
%\boldsymbol{\varepsilon}_i &\overset{iid}\sim N(\mathbf{0}, \, \sigma^2
|
||||
\varepsilon_{ij} &\overset{iid}{\sim} N(0, \sigma^2_\varepsilon)
|
||||
\mathbf{I}_{n_i})
|
||||
\end{align*}
|
||||
\end{column}
|
||||
@@ -518,27 +519,28 @@ with
|
||||
\sigma_{\upsilon_0 \upsilon_1} & \sigma^2_{\upsilon_1} & \sigma_{\upsilon_1 \upsilon_2}\\
|
||||
\sigma_{\upsilon_0 \upsilon_2} & \sigma_{\upsilon_1 \upsilon_2} & \sigma^2_{\upsilon_2}\\
|
||||
\end{pmatrix} \right) \\
|
||||
\boldsymbol{\varepsilon}_i &\overset{iid}{\sim} N(\mathbf{0}, \, \sigma^2 \mathbf{I}_{n_i})
|
||||
%\boldsymbol{\varepsilon}_{ij} &\overset{iid}{\sim} N(\mathbf{0}, \, \sigma^2 \mathbf{I}_{n_i})
|
||||
\varepsilon_{ij} &\overset{iid}{\sim} N(0, \sigma^2_\varepsilon)
|
||||
\end{align*}
|
||||
\end{itemize}
|
||||
\vspace{-.5cm}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]{Model with quadratic trend}
|
||||
\begin{lstlisting}
|
||||
library("lme4")
|
||||
|
||||
# random intercept model
|
||||
lme1 <- lmer(hamd ~ week + (1 | id), data = dat, REML = FALSE)
|
||||
|
||||
# random slope model
|
||||
lme2 <- lmer(hamd ~ week + (week | id), data = dat, REML = FALSE)
|
||||
|
||||
# model with quadratic time trend
|
||||
lme3 <- lmer(hamd ~ week + I(week^2) + (week + I(week^2) | id),
|
||||
data = dat, REML = FALSE)
|
||||
\end{lstlisting}
|
||||
\end{frame}
|
||||
% \begin{frame}[fragile]{Model with quadratic trend}
|
||||
% \begin{lstlisting}
|
||||
% library("lme4")
|
||||
%
|
||||
% # random intercept model
|
||||
% lme1 <- lmer(hamd ~ week + (1 | id), data = dat, REML = FALSE)
|
||||
%
|
||||
% # random slope model
|
||||
% lme2 <- lmer(hamd ~ week + (week | id), data = dat, REML = FALSE)
|
||||
%
|
||||
% # model with quadratic time trend
|
||||
% lme3 <- lmer(hamd ~ week + I(week^2) + (week + I(week^2) | id),
|
||||
% data = dat, REML = FALSE)
|
||||
% \end{lstlisting}
|
||||
% \end{frame}
|
||||
|
||||
\begin{frame}{Model predictions}
|
||||
\begin{columns}
|
||||
@@ -575,7 +577,6 @@ xyplot(
|
||||
~ week | id,
|
||||
data = dat,
|
||||
type = c("p", "l", "g"),
|
||||
pch = 16,
|
||||
distribute.type = TRUE,
|
||||
ylab = "HDRS score",
|
||||
xlab = "Time (Week)")
|
||||
@@ -663,29 +664,21 @@ xyplot(
|
||||
\end{block}
|
||||
\end{frame}
|
||||
|
||||
\begin{frame}[fragile]{Analysis with centered time variable}
|
||||
\begin{lstlisting}
|
||||
dat$week_c <- dat$week - mean(dat$week)
|
||||
cor(dat$week, dat$week^2) # 0.96
|
||||
cor(dat$week_c, dat$week_c^2) # 0.01
|
||||
|
||||
# random slope model
|
||||
lme2c <- lmer(hamd ~ week_c + (week_c | id), data = dat, REML = FALSE)
|
||||
|
||||
# model with quadratic time trend
|
||||
lme3c <- lmer(hamd ~ week_c + I(week_c^2) + (week_c + I(week_c^2)|id),
|
||||
data = dat, REML = FALSE)
|
||||
\end{lstlisting}
|
||||
% \begin{itemize}
|
||||
% \item When comparing the estimated parameters, it becomes obvious that not
|
||||
% only the intercept changes but the estimates for the (co)variances do as
|
||||
% well
|
||||
% \item Why?\pause
|
||||
% ~Be sure to make an informed choice when centering your
|
||||
% variables!
|
||||
% \end{itemize}
|
||||
\nocite{Alday2025, Hedeker2006}
|
||||
\end{frame}
|
||||
% \begin{frame}[fragile]{Analysis with centered time variable}
|
||||
% \begin{lstlisting}
|
||||
% dat$week_c <- dat$week - mean(dat$week)
|
||||
% cor(dat$week, dat$week^2) # 0.96
|
||||
% cor(dat$week_c, dat$week_c^2) # 0.01
|
||||
%
|
||||
% # random slope model
|
||||
% lme2c <- lmer(hamd ~ week_c + (week_c | id), data = dat, REML = FALSE)
|
||||
%
|
||||
% # model with quadratic time trend
|
||||
% lme3c <- lmer(hamd ~ week_c + I(week_c^2) + (week_c + I(week_c^2)|id),
|
||||
% data = dat, REML = FALSE)
|
||||
% \end{lstlisting}
|
||||
% \nocite{Alday2025, Hedeker2006}
|
||||
% \end{frame}
|
||||
|
||||
\begin{frame}[fragile]{Investigating random effects structure}
|
||||
\begin{itemize}
|
||||
@@ -697,8 +690,12 @@ lme3c <- lmer(hamd ~ week_c + I(week_c^2) + (week_c + I(week_c^2)|id),
|
||||
\end{itemize}
|
||||
\vfill
|
||||
\begin{lstlisting}
|
||||
# model with quadratic time trend
|
||||
m <- lmer(hamd ~ week + I(week^2) + (week + I(week^2) | id),
|
||||
data = dat, REML = FALSE)
|
||||
|
||||
library("lattice")
|
||||
dotplot(ranef(lme3), scales = list( x = list(relation = "free")))$id
|
||||
dotplot(ranef(m), scales = list( x = list(relation = "free")))$id
|
||||
\end{lstlisting}
|
||||
\end{frame}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user