Update slides
This commit is contained in:
Binary file not shown.
@@ -173,7 +173,7 @@ xyplot(Reaction ~ Days | Subject,
|
|||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
\item The random intercept model adds a random intercept for each subject
|
\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})$,
|
with $\upsilon_{0i} \overset{iid}{\sim} N(0, \sigma^2_{\upsilon})$,
|
||||||
$\varepsilon_{ij} \overset{iid}{\sim} N(0, \sigma^2_\varepsilon)$
|
$\varepsilon_{ij} \overset{iid}{\sim} N(0, \sigma^2_\varepsilon)$
|
||||||
@@ -455,7 +455,7 @@ with
|
|||||||
\end{column}
|
\end{column}
|
||||||
\begin{column}{.4\textwidth}
|
\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}
|
\varepsilon_{ij}
|
||||||
\]
|
\]
|
||||||
with
|
with
|
||||||
@@ -466,7 +466,8 @@ with
|
|||||||
\sigma^2_{\upsilon_0} & \sigma_{\upsilon_0 \upsilon_1} \\
|
\sigma^2_{\upsilon_0} & \sigma_{\upsilon_0 \upsilon_1} \\
|
||||||
\sigma_{\upsilon_0 \upsilon_1} & \sigma^2_{\upsilon_1} \\
|
\sigma_{\upsilon_0 \upsilon_1} & \sigma^2_{\upsilon_1} \\
|
||||||
\end{pmatrix} \right)\\
|
\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})
|
\mathbf{I}_{n_i})
|
||||||
\end{align*}
|
\end{align*}
|
||||||
\end{column}
|
\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_1} & \sigma^2_{\upsilon_1} & \sigma_{\upsilon_1 \upsilon_2}\\
|
||||||
\sigma_{\upsilon_0 \upsilon_2} & \sigma_{\upsilon_1 \upsilon_2} & \sigma^2_{\upsilon_2}\\
|
\sigma_{\upsilon_0 \upsilon_2} & \sigma_{\upsilon_1 \upsilon_2} & \sigma^2_{\upsilon_2}\\
|
||||||
\end{pmatrix} \right) \\
|
\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{align*}
|
||||||
\end{itemize}
|
\end{itemize}
|
||||||
\vspace{-.5cm}
|
\vspace{-.5cm}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
\begin{frame}[fragile]{Model with quadratic trend}
|
% \begin{frame}[fragile]{Model with quadratic trend}
|
||||||
\begin{lstlisting}
|
% \begin{lstlisting}
|
||||||
library("lme4")
|
% library("lme4")
|
||||||
|
%
|
||||||
# random intercept model
|
% # random intercept model
|
||||||
lme1 <- lmer(hamd ~ week + (1 | id), data = dat, REML = FALSE)
|
% lme1 <- lmer(hamd ~ week + (1 | id), data = dat, REML = FALSE)
|
||||||
|
%
|
||||||
# random slope model
|
% # random slope model
|
||||||
lme2 <- lmer(hamd ~ week + (week | id), data = dat, REML = FALSE)
|
% lme2 <- lmer(hamd ~ week + (week | id), data = dat, REML = FALSE)
|
||||||
|
%
|
||||||
# model with quadratic time trend
|
% # model with quadratic time trend
|
||||||
lme3 <- lmer(hamd ~ week + I(week^2) + (week + I(week^2) | id),
|
% lme3 <- lmer(hamd ~ week + I(week^2) + (week + I(week^2) | id),
|
||||||
data = dat, REML = FALSE)
|
% data = dat, REML = FALSE)
|
||||||
\end{lstlisting}
|
% \end{lstlisting}
|
||||||
\end{frame}
|
% \end{frame}
|
||||||
|
|
||||||
\begin{frame}{Model predictions}
|
\begin{frame}{Model predictions}
|
||||||
\begin{columns}
|
\begin{columns}
|
||||||
@@ -575,7 +577,6 @@ xyplot(
|
|||||||
~ week | id,
|
~ week | id,
|
||||||
data = dat,
|
data = dat,
|
||||||
type = c("p", "l", "g"),
|
type = c("p", "l", "g"),
|
||||||
pch = 16,
|
|
||||||
distribute.type = TRUE,
|
distribute.type = TRUE,
|
||||||
ylab = "HDRS score",
|
ylab = "HDRS score",
|
||||||
xlab = "Time (Week)")
|
xlab = "Time (Week)")
|
||||||
@@ -663,29 +664,21 @@ xyplot(
|
|||||||
\end{block}
|
\end{block}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
\begin{frame}[fragile]{Analysis with centered time variable}
|
% \begin{frame}[fragile]{Analysis with centered time variable}
|
||||||
\begin{lstlisting}
|
% \begin{lstlisting}
|
||||||
dat$week_c <- dat$week - mean(dat$week)
|
% dat$week_c <- dat$week - mean(dat$week)
|
||||||
cor(dat$week, dat$week^2) # 0.96
|
% cor(dat$week, dat$week^2) # 0.96
|
||||||
cor(dat$week_c, dat$week_c^2) # 0.01
|
% cor(dat$week_c, dat$week_c^2) # 0.01
|
||||||
|
%
|
||||||
# random slope model
|
% # random slope model
|
||||||
lme2c <- lmer(hamd ~ week_c + (week_c | id), data = dat, REML = FALSE)
|
% lme2c <- lmer(hamd ~ week_c + (week_c | id), data = dat, REML = FALSE)
|
||||||
|
%
|
||||||
# model with quadratic time trend
|
% # model with quadratic time trend
|
||||||
lme3c <- lmer(hamd ~ week_c + I(week_c^2) + (week_c + I(week_c^2)|id),
|
% lme3c <- lmer(hamd ~ week_c + I(week_c^2) + (week_c + I(week_c^2)|id),
|
||||||
data = dat, REML = FALSE)
|
% data = dat, REML = FALSE)
|
||||||
\end{lstlisting}
|
% \end{lstlisting}
|
||||||
% \begin{itemize}
|
% \nocite{Alday2025, Hedeker2006}
|
||||||
% \item When comparing the estimated parameters, it becomes obvious that not
|
% \end{frame}
|
||||||
% 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]{Investigating random effects structure}
|
\begin{frame}[fragile]{Investigating random effects structure}
|
||||||
\begin{itemize}
|
\begin{itemize}
|
||||||
@@ -697,8 +690,12 @@ lme3c <- lmer(hamd ~ week_c + I(week_c^2) + (week_c + I(week_c^2)|id),
|
|||||||
\end{itemize}
|
\end{itemize}
|
||||||
\vfill
|
\vfill
|
||||||
\begin{lstlisting}
|
\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")
|
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{lstlisting}
|
||||||
\end{frame}
|
\end{frame}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user