\documentclass{article}
\newcommand{\titel}{\pkg{lavaan}: an \proglang{R} package for structural equation modeling}
%\usepackage{Sweave}
\usepackage{fancyvrb}
\usepackage{graphicx}
\usepackage{color}


\usepackage{times}
\usepackage{sectsty}
\usepackage{tikz}
\tikzstyle{ov}=[shape=rectangle,
                draw=black!80,
                minimum height=0.6cm,
                minimum width=0.6cm,
                thick]

\tikzstyle{av}=[shape=rectangle,
                draw=black!80,
                fill=black!10,
                minimum height=0.6cm,
                minimum width=0.6cm,
                thick]

\tikzstyle{lv}=[shape=circle,draw=black!80,thick,minimum width=0.7cm]


\fvset{fontfamily=courier}
\DefineVerbatimEnvironment{Sinput}{Verbatim}
{fontseries=b, fontsize=\footnotesize, xleftmargin=0.2cm}
\DefineVerbatimEnvironment{Routput}{Verbatim}
{fontsize=\footnotesize, xleftmargin=1cm}
\DefineVerbatimEnvironment{Routput}{Verbatim}
{fontseries=b,fontsize=\scriptsize, xleftmargin=0.2cm}
\DefineVerbatimEnvironment{Binput}{Verbatim}
{fontseries=b, fontsize=\scriptsize,frame=single, label=\fbox{lavaan model syntax}, framesep=2mm}
%\DefineShortVerb{\!}
\DefineVerbatimEnvironment{Rinput}{Verbatim}
{fontseries=b, fontsize=\scriptsize, frame=single, label=\fbox{R code}, framesep=5mm}


\newcommand{\pkg}[1]{{\normalfont\fontseries{b}\selectfont #1}}
\let\proglang=\textsf
\let\code=\texttt

\usepackage{bm}
\renewcommand{\v}[1]{\ensuremath{\bm{\mathrm{#1}}}}

% colors
\definecolor{darkred}{rgb}{.4, .0, .0}
\definecolor{darkblue}{rgb}{.0, .0, .4}
\definecolor{darkgreen}{rgb}{.0, .3, .0}
\definecolor{darkgray}{rgb}{.6, .6, .6}
\definecolor{brown}{rgb}{.3, .3, .0}
\subsectionfont{\color{darkgreen}}
\sectionfont{\color{darkblue}}
\subsubsectionfont{\sffamily\color{brown}}

\usepackage{geometry}
\geometry{paperwidth=12.8cm, paperheight=9.6cm,
          includeheadfoot,
          scale={0.90,0.95},
          headsep=0.3cm,footskip=0.4cm
         }

\usepackage{fancyhdr}
\usepackage{lastpage}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0.1mm}
\renewcommand{\footrulewidth}{0.1mm}
\lhead{\tiny \sffamily Department of Data Analysis}
\chead{}
\rhead{\tiny \sffamily Ghent University}
\lfoot{\tiny \sffamily Yves Rosseel}
\cfoot{\tiny \sffamily \textcolor{darkred}{\titel}}
\rfoot{\tiny \sffamily \thepage\ / {\normalcolor \pageref{LastPage}}}

\usepackage{booktabs}
\renewcommand{\arraystretch}{1.2}



\author{Yves Rosseel\\
Department of Data Analysis\\
Ghent University -- Belgium}
\date{\vspace*{1cm}Utrecht -- April 24, 2012}
\title{\textcolor{darkred}{\titel}}

\newcommand{\sss}[1]{\subsubsection*{#1}}
\newcommand{\lijn}{\mbox{}\\*[0.04\textheight]}


\begin{document}
\maketitle\thispagestyle{fancy}\newpage
%\tableofcontents\newpage

\subsection*{Overview}
\begin{enumerate}
\item software for SEM
\item what is lavaan? why do we need lavaan?
\item features of lavaan
\item lavaan and the (computational) history of SEM
\end{enumerate}


%\newpage
%\subsection*{Structural Equation Modeling}
%\begin{itemize}
%\item path analysis with latent variables
%\end{itemize}
%\begin{center}
%\begin{tikzpicture}[>=stealth,semithick]
%\node[ov] (y1) at (0,-1)      {$y_1$};
%\node[ov] (y2) [below of=y1]  {$y_2$};
%\node[ov] (y3) [below of=y2]  {$y_3$};
%\node[ov] (y4) [below of=y3]  {$y_4$};
%\node[ov] (y5) [below of=y4]  {$y_5$};
%\node[ov] (y6) [below of=y5]  {$y_6$};
%
%\node[lv] (f1) at (1.5, -2)  {$\eta_1$};
%\node[lv] (f2) at (1.5, -5)  {$\eta_2$};
%
%\node[ov] (y7)  at (3,0)        {$y_7$};
%\node[ov] (y8)  [right of=y7]   {$y_8$};
%\node[ov] (y9)  [right of=y8]   {$y_9$};
%\node[ov] (y10) [right of=y9]   {$y_{10}$};
%\node[ov] (y11) [right of=y10]  {$y_{11}$};
%\node[ov] (y12) [right of=y11]  {$y_{12}$};
%
%\node[lv] (f3) at (4, -2) {$\eta_3$};
%\node[lv] (f4) at (7, -2) {$\eta_4$};
%
%\path[->] (f1) edge node[above,scale=0.6] {} (y1)
%          (f1) edge node[above,scale=0.6] {} (y2)
%          (f1) edge node[above,scale=0.6] {} (y3)
%          (f2) edge node[above,scale=0.6] {} (y4)
%          (f2) edge node[above,scale=0.6] {} (y5)
%          (f2) edge node[above,scale=0.6] {} (y6)
%
%          (f3) edge node[above,scale=0.6] {} (y7)
%          (f3) edge node[above,scale=0.6] {} (y8)
%          (f3) edge node[above,scale=0.6] {} (y9)
%          (f4) edge node[above,scale=0.6] {} (y10)
%          (f4) edge node[above,scale=0.6] {} (y11)
%          (f4) edge node[above,scale=0.6] {} (y12)
%
%          (f1) edge node[above,scale=0.6] {} (f3)
%          (f2) edge node[above,scale=0.6] {} (f3)
%          (f3) edge node[above,scale=0.6] {} (f4);
%\end{tikzpicture}
%\end{center}

\newpage
\subsection*{Software for SEM (commercial)}
\sss{The big four}
\begin{itemize}
\item LISREL
\item EQS
\item AMOS
\item MPLUS
\end{itemize}
\sss{Others}
\begin{itemize}
\item CALIS/TCALIS (SAS/Stat)
\item SEPATH (Statistica)
\item RAMONA (Systat)
\item Stata 12
\item \ldots
\end{itemize}

\newpage
\subsection*{Software for SEM: non-commercial}
\begin{itemize}
\item outside the R ecosystem: Mx, gllamm (Stata), \ldots
\item three R packages: 
\begin{enumerate}
\item sem
\begin{itemize}
\item developer: John Fox (since 2001)
\item for a long time the only option in R
\end{itemize}
\item OpenMx
\begin{itemize}
\item Mx reborn -- website: \verb!http://openmx.psyc.virginia.edu/!
\item free, but the solver (NPSOL) is (currently) not open-source
\end{itemize}
\item lavaan
\begin{itemize}
\item first public release: May 2010 (version 0.3-1)
\item current version: 0.4-13
\end{itemize}
\end{enumerate}
\item interfaces between R and commercial packages:
\begin{itemize}
\item \code{REQS}, \code{MplusAutomation}
\end{itemize}
\end{itemize}


\newpage
\subsection*{What is lavaan?}
\begin{itemize}
\item \pkg{lavaan} is an R package for latent variable analysis:
\begin{itemize}
\item confirmatory factor analysis: function \code{cfa()}
\item structural equation modeling: function \code{sem()}
\item latent curve analysis / growth modeling: function \code{growth()}
\item general mean/covariance structure modeling: function \code{lavaan()}
\item (item response theory (IRT) models)
\item (latent class + mixture models)
\item (multilevel models)
\end{itemize}
\item  the \pkg{lavaan} package is developed to provide useRs, researchers and
teachers a free, open-source, but commercial-quality package for latent
variable modeling
\item the long-term goal of \pkg{lavaan} is to implement all
the state-of-the-art capabilities that are currently available in commercial
packages
\end{itemize}

\newpage
\subsection*{Installing \pkg{lavaan}, finding documentation}
\begin{itemize}
\item \pkg{lavaan} depends on the R project for statistical computing:
\begin{quote}
\Verb!http://www.r-project.org!
\end{quote}
\item to install \pkg{lavaan}, simply start up an R session and type:
\begin{Sinput}
> install.packages("lavaan")
\end{Sinput}
\item more information about \pkg{lavaan}:
\begin{quote}
\Verb!http://lavaan.org!
\end{quote}
\item journal paper:
    \begin{quote}
     Rosseel (2012). lavaan: an R package for structural equation modeling.
    {\itshape Journal of Statistical Software}, (??), ??--??.
\end{quote}
\item \pkg{lavaan} development:
\begin{quote}
\Verb!https://github.com/yrosseel/lavaan!
\end{quote}
\end{itemize}

\newpage
\subsection*{Why do we need \pkg{lavaan}?}
\begin{enumerate}
\item lavaan is for statisticians working in the field of SEM
\begin{itemize}
\item it seems unfortunate that new developments in this field are hindered by
the lack of open source software that researchers can use to implement their
newest ideas
\end{itemize}
\item lavaan is for teachers
\begin{itemize}
\item teaching these techniques to students was often
complicated by the forced choice for one of the commercial packages
\end{itemize}
\item lavaan is for applied researchers
\begin{itemize}
\item keep it simple, provide all the features they need
\end{itemize}
\end{enumerate}

\newpage
\subsection*{Features of lavaan}
\vspace*{1cm}
\sss{\pkg{lavaan} is reliable and robust}
\begin{itemize}
\item extensive testing before a `public' release on CRAN
\item no convergence problems (for admissible models)
\item numerical results are very close (if not identical) to commercial
packages:
\begin{itemize}
\item Mplus (if \code{mimic="Mplus"}, default)
\item EQS (if \code{mimic="EQS"})
\end{itemize}
\end{itemize}

\newpage
\sss{the lavaan model syntax}
{\scriptsize
\begin{center}
\begin{tabular}{p{0.35\textwidth}p{0.59\textwidth}} \hline
\begin{center}
\begin{tikzpicture}[>=stealth,semithick,scale=0.5]
\node[ov] (y1) at (0,0)     {\code{x1}};
\node[ov] (y2) at (0,-1.4)  {\code{x2}};
\node[ov] (y3) at (0,-2.8)  {\code{x3}};
\node[ov] (y4) at (0,-4.2)  {\code{x4}};
\node[ov] (y5) at (0,-5.6)  {\code{x5}};
\node[ov] (y6) at (0,-7)    {\code{x6}};
\node[ov] (y7) at (0,-8.4)  {\code{x7}};
\node[ov] (y8) at (0,-9.8)  {\code{x8}};
\node[ov] (y9) at (0,-11.2) {\code{x9}};
\node[lv] (f1) at (4, -1.4) {\code{visual}};
\node[lv] (f2) at (4, -5.6) {\code{textual}};
\node[lv] (f3) at (4, -9.8) {\code{speed}};
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y1.east);
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y2.east);
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y3.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y4.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y5.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y6.east);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y7.east);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y8.east);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y9.east);
\path[<->] (f1.south east) edge [bend left=45] node[left,scale=0.8] {} (f2.north east);
\path[<->] (f1.east) edge [bend left=45] node[left,scale=0.8] {} (f3.east);
\path[<->] (f2.south east) edge [bend left=45] node[left,scale=0.8] {} (f3.north east);
\end{tikzpicture}
\end{center}
&
\begin{Sinput}
HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9
            '
            
fit <- cfa(model = HS.model, 
           data  = HolzingerSwineford1939)

summary(fit, fit.measures = TRUE, 
             standardized = TRUE)
\end{Sinput}
\\ \hline
\end{tabular}
\end{center}
}

\newpage
\sss{lavaan output}
\begin{Routput}
lavaan (0.4-13) converged normally after 41 iterations

  Number of observations                           301

  Estimator                                         ML
  Minimum Function Chi-square                   85.306
  Degrees of freedom                                24
  P-value                                        0.000

Chi-square test baseline model:

  Minimum Function Chi-square                  918.852
  Degrees of freedom                                36
  P-value                                        0.000

Full model versus baseline model:

  Comparative Fit Index (CFI)                    0.931
  Tucker-Lewis Index (TLI)                       0.896

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3737.745
  Loglikelihood unrestricted model (H1)      -3695.092

  Number of free parameters                         21
  Akaike (AIC)                                7517.490
  Bayesian (BIC)                              7595.339
  Sample-size adjusted Bayesian (BIC)         7528.739

Root Mean Square Error of Approximation:

  RMSEA                                          0.092
  90 Percent Confidence Interval          0.071  0.114
  P-value RMSEA <= 0.05                          0.001

Standardized Root Mean Square Residual:

  SRMR                                           0.065

Parameter estimates:

  Information                                 Expected
  Standard Errors                             Standard

                   Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
Latent variables:
  visual =~
    x1                1.000                               0.900    0.772
    x2                0.553    0.100    5.554    0.000    0.498    0.424
    x3                0.729    0.109    6.685    0.000    0.656    0.581
  textual =~
    x4                1.000                               0.990    0.852
    x5                1.113    0.065   17.014    0.000    1.102    0.855
    x6                0.926    0.055   16.703    0.000    0.917    0.838
  speed =~
    x7                1.000                               0.619    0.570
    x8                1.180    0.165    7.152    0.000    0.731    0.723
    x9                1.082    0.151    7.155    0.000    0.670    0.665

Covariances:
  visual ~~
    textual           0.408    0.074    5.552    0.000    0.459    0.459
    speed             0.262    0.056    4.660    0.000    0.471    0.471
  textual ~~
    speed             0.173    0.049    3.518    0.000    0.283    0.283

Variances:
    x1                0.549    0.114                      0.549    0.404
    x2                1.134    0.102                      1.134    0.821
    x3                0.844    0.091                      0.844    0.662
    x4                0.371    0.048                      0.371    0.275
    x5                0.446    0.058                      0.446    0.269
    x6                0.356    0.043                      0.356    0.298
    x7                0.799    0.081                      0.799    0.676
    x8                0.488    0.074                      0.488    0.477
    x9                0.566    0.071                      0.566    0.558
    visual            0.809    0.145                      1.000    1.000
    textual           0.979    0.112                      1.000    1.000
    speed             0.384    0.086                      1.000    1.000
\end{Routput}

\newpage
\sss{lavaan model syntax (2)}
{\scriptsize
\begin{center}
\begin{tabular}{p{0.55\textwidth}p{0.40\textwidth}} \hline
\begin{center}
\begin{tikzpicture}[>=stealth,semithick,scale=0.5]
\node[ov] (y1) at (0,0)     {\code{y1}};
\node[ov] (y2) at (0,-1.4)  {\code{y2}};
\node[ov] (y3) at (0,-2.8)  {\code{y3}};
\node[ov] (y4) at (0,-4.2)  {\code{y4}};
\node[ov] (y5) at (0,-5.6)  {\code{y5}};
\node[ov] (y6) at (0,-7)    {\code{y6}};
\node[ov] (y7) at (0,-8.4)  {\code{y7}};
\node[ov] (y8) at (0,-9.8)  {\code{y8}};
\node[ov] (x1) at ( 6,0)     {\code{x1}};
\node[ov] (x2) at ( 8,0)     {\code{x2}};
\node[ov] (x3) at (10,0)     {\code{x3}};
\node[lv] (f1) at (4, -2.8) {\code{dem60}};
\node[lv] (f2) at (4, -7.6) {\code{dem65}};
\node[lv] (f3) at (8, -2.8) {\code{ind60}};
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y1.east);
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y2.east);
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y3.east);
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y4.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y5.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y6.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y7.east);
\path[->] (f2) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (y8.east);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (x1.south);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (x2.south);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (x3.south);
\path[->] (f1) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (f2);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (f1.east);
\path[->] (f3) edge node[above=0.08cm,scale=0.8,pos=0.7] {} (f2.north east);
\path[<->] (y1.west) edge [bend right=45] node[left,scale=0.8] {} (y5.west);
\path[<->] (y2.west) edge [bend right=45] node[left,scale=0.8] {} (y6.west);
\path[<->] (y3.west) edge [bend right=45] node[left,scale=0.8] {} (y7.west);
\path[<->] (y4.west) edge [bend right=45] node[left,scale=0.8] {} (y8.west);
\path[<->] (y2.south west) edge [bend right=45] node[left,scale=0.8] {} (y4.north west);
\path[<->] (y6.south west) edge [bend right=45] node[left,scale=0.8] {} (y8.north west);
\end{tikzpicture}
\end{center}
&
\begin{Binput}


# latent variable definitions
  ind60 =~ x1 + x2 + x3
  dem60 =~ y1 + y2 + y3 + y4
  dem65 =~ y5 + y6 + y7 + y8

# regressions
  dem60 ~ ind60
  dem65 ~ ind60 + dem60

# residual covariances
  y1 ~~ y5
  y2 ~~ y4
  y2 ~~ y6
  y3 ~~ y7
  y4 ~~ y8
  y6 ~~ y8
\end{Binput}
\\
\end{tabular}
\end{center}
}

\newpage
\sss{lavaan features (0.4)}
\sss{support for non-normal continuous data}
\begin{itemize}
\item asymptotically distribution-free (ADF) estimation (Browne 1984)
\item Satorra-Bentler scaled test statistic and robust standard errors
\item Yuan-Bentler scaled test statistic and robust standard errors when
data are both non-normal and missing (at random)
\item bootstrapping: the na\"{i}ve bootstrap and the Bollen-Stine bootstrap
\end{itemize}
\sss{support for missing data (fiml)}
\sss{multiple groups and measurement invariance}
\sss{linear and nonlinear equality and inequality constraints}
\sss{defined parameters and mediation analysis}
\sss{bootstrapping}

\newpage
\sss{what to expect in lavaan 0.5}
\begin{itemize}
\item expected release: 11 May 2012
\item support for categorical data (three-step/WLS approach)
\item modularity + access to all lavaan internals
\end{itemize}

\sss{what to expect in lavaan 0.6-0.7}
\begin{itemize}
\item Bayesian estimation
\item support for multilevel data
\item speed!
\item \ldots
\item technical documentation
\end{itemize}

\newpage
\subsection*{The history of SEM, from a computational point of view}
\begin{itemize}
\item several traditions in the SEM (software) world:
\begin{itemize}
\item LISREL (Karl J\"{o}reskog)
\item EQS (Peter Bentler)
\item Mplus (Bengt Muth\'{e}n)
\item RAM-based approaches (AMOS, Mx, sem, OpenMx, \ldots)
\end{itemize}
\item superficially, all SEM software packages produce the same results
\item there are some subtle (and less subtle) differences in the output
\item looking deeper, there are many computational differences
\end{itemize}

\newpage
\sss{some differences}
\begin{itemize}
\item matrix representation
\begin{itemize}
\item standard number of matrices: LISREL: 8; Mplus: 4, EQS: 3, RAM: 2
\end{itemize}
\item optimization algorithm
\begin{itemize}
\item quasi-Newton, gradient-only + quasi-Newton, Gauss-Newton, \ldots
\end{itemize}
\item variances constrained (strictly positive) versus unrestricted
\item constrained optimization algorithm
\begin{itemize}
\item mostly undocumented
\item a Lagrangian-multiplier variant, simple slacks, \ldots
\end{itemize}
\item normal likelihood versus Wishart likelihood, ML versus GLS-ML (RLS)
\begin{itemize}
\item $N$ versus $N-1$
\item GLS-ML based chi-square test statistic influences fit measures (CFI!)
\end{itemize}
\end{itemize}

\newpage
\sss{some differences (2)}
\begin{itemize}

\item Satorra-Bentler/Yuan-Bentler scaled test statistic
\begin{itemize}
\item each program seems to use a different implementation
\item often asymptotically equivalent; but large differences
in small samples
\end{itemize}
\item categorical data using the limited information approach
\begin{itemize}
\item Muth\'{e}n 1984; J\"{o}reskog 1994; Lee, Poon, Bentler (1992)
\item many ways to compute the asymptotic covariance matrix (needed for WLS)
\end{itemize}
\item naive bootstrapping, Bollen-Stine bootstrapping
\begin{itemize}
\item mostly undocumented; one-iteration bootstrap?
\item Bollen-Stine with missing data
\end{itemize}
\ldots
\end{itemize}

\newpage
\subsection*{lavaan and the history of SEM}
\begin{itemize}
\item lavaan is in many areas still trying to catch up with commercial
software; but instead of trying to implement one tradition (based on one
program), lavaan tries to implement several traditions
\item all fitting functions in lavaan have a \code{mimic} argument which
can be set to \code{"EQS"} or \code{"Mplus"} respectively;
\code{"LISREL"} is under development
\item this was originally intended to convince users that lavaan could
produce `identical' results as the (commercial) competition
\item it is now one of the main design goals of lavaan
\end{itemize}

\subsection*{lavaan and the future of SEM?}
\begin{itemize}
\item we need to (re)evaluate old/new/unexplored computational methods in many
areas (optimization, constrained inference, Bayesian techniques, limited
information estimation, \ldots)
\item lavaan should `by default' implement best practices in all areas
\end{itemize}

\newpage
\vspace*{2cm}
\begin{center}
\subsection*{End of part I}
\end{center}


\end{document}
