% \VignetteIndexEntry{Addiction - Multinomial Model with Hierarchically Structured Response}
% \VignetteDepends{nnet}
%\VignetteEngine{knitr::knitr}
%\VignetteEncoding{UTF-8}
\documentclass[a4paper]{article}

\title{Addiction - Multinomial Model with Hierarchically Structured Response}

\begin{document}

\maketitle


<<echo=FALSE,eval=FALSE>>=
rm(list=ls(all=TRUE))
options(width=60)
@

First the "addiction" data are loaded and attached.

<<results='hide',eval=FALSE>>=
library(catdata)
data(addiction)
attach(addiction)
@

For the Multinomial Model with hierarchically structured response we use simple Logit Models. For the first model, which models the effect of categories 
0 and 1 versus 2, a new response "ill01" is created. In addition the variable "age2" for the squared effect of age is created.

<<eval=FALSE>>=
ill01 <- ill
ill01[ill==0] <- 1
ill01[ill==2] <- 0

age2 <- age^2
@

Now the model for categories 0 and 1 versus 2 is fitted.

<<eval=FALSE>>=
m01vs2 <- glm(ill01 ~ as.factor(gender) + as.factor(university) + age + age2, 
family=binomial())
summary(m01vs2)
@

For the next model the data set has to be reduced, only observations with response categories 0 or 1 are needed. Then the variable "age2" is built.

<<results='hide',eval=FALSE>>=
detach(addiction)
addiction2 <- addiction[addiction$ill!=2,]
attach(addiction2)
age2 <- age^2
@

Finally the model for categories 0 versus 1 is fitted.

<<eval=FALSE>>=
m0vs1 <- glm(ill ~ as.factor(gender) + as.factor(university) + age + age2, 
family=binomial())
summary(m0vs1)
@

\end{document}
