\SweaveOpts{results=hide, prefix.string=vigpics/gammanet}
\include{zinput}
%\VignetteIndexEntry{Network Gamma Regression for Continuous, Positive Proximity Matrix Dependent Variables}
%\VignetteDepends{Zelig, stats}
%\VignetteKeyWords{model,least squares,continuous, regression}
%\VignettePackage{Zelig}
\begin{document}
\nobibliography* 
<<beforepkgs, echo=FALSE>>=
 before=search()
@ 
<<loadLibrary, echo=F,results=hide>>= 
library(Zelig) 
@  
 
\section{{\tt gamma.net}: Network Gamma Regression for Continuous, Positive Proximity Matrix Dependent Variables} 
 
Use the network gamma regression model if you have a positive-valued dependent variable that is a binary valued proximity matrix (a.k.a. sociomatricies, adjacency matrices, or matrix representations of directed graphs). The gamma distribution assumes that all waiting times are complete by the end of the study (censoring is not allowed). 
 
\subsubsection{Syntax} 
\begin{verbatim} 
> z.out <- zelig(y ~ x1 + x2, model = "gamma.net", data = mydata)  
> x.out <- setx(z.out) 
> s.out <- sim(z.out, x = x.out) 
\end{verbatim} 
 
\subsubsection{Additional Inputs} 
 
In addition to the standard inputs, {\tt zelig()} takes the following additional options for network gamma regression: 
 
\begin{itemize} 
\item {\tt LF}: specifies the link function to be used for the network gamma regression. Default is {\tt LF="inverse"}, but {\tt LF} can also be set to {\tt "identity"} or {\tt "log"} by the user. 
\end{itemize} 
 
\subsubsection{Examples} 
\begin{enumerate} 
\item Basic Example 
 
Load the sample data (see {\tt ?friendship} for details on the structure of the network dataframe): 
 
<<echo=TRUE, results=hide, fig=FALSE>>= 
data(friendship) 
 
 
 
@ 
Estimate model: 
 
<<echo=TRUE, results=hide, fig=FALSE>>= 
z.out <- zelig(per ~ perpower, LF="inverse",  model="gamma.net", data=friendship) 
summary(z.out) 
 
@ 
Setting values for the explanatory variables to their default values: 
 
<<echo=TRUE, results=hide, fig=FALSE>>= 
x.out <- setx(z.out) 
 
@ 
Simulating quantities of interest from the posterior distribution. 
<<echo=TRUE, results=hide, fig=FALSE>>= 
s.out <- sim(z.out, x = x.out)  
summary(s.out)  
plot(s.out)  
@ 
 
\begin{figure}[here] 
\centering 
<<fig=TRUE, width=12, echo=false, height=6>>= 
plot(s.out) 
@ 
\label{fig:plotgam} 
\end{figure} 
 
 
\item Simulating First Differences 
 
<<echo=TRUE, results=hide, fig=FALSE>>= 
x.low <- setx(z.out, numst2 = 0) 
x.high <- setx(z.out, numst2 = 1) 
 
s.out2 <- sim(z.out, x = x.low, x1 = x.high)    
summary(s.out2)    
plot(s.out2)    
 
@ 
 
\begin{figure}[here] 
\centering 
<<fig=TRUE, echo=false, width=12, height=6>>= 
plot(s.out) 
@ 
\label{fig:plotgam} 
\end{figure} 
 
\end{enumerate} 
 
 
 
\subsubsection{Model} 
The {\tt gamma.net} model performs a gamma regression of the proximity matrix $\mathbf{Y}$, a $m \times m$ matrix representing network ties, on a set of proximity matrices $\mathbf{X}$. This network regression model is directly analogous to standard gamma regression element-wise on the appropriately vectorized matrices. Proximity matrices are vectorized by creating $Y$, a $m^2 \times 1$ vector to represent the proximity matrix. The vectorization which produces the $Y$ vector from the $\mathbf{Y}$ matrix is performed by simple row-concatenation of $\mathbf{Y}$. For example, if $\mathbf{Y}$ is a $15 \times 15$ matrix, the $\mathbf{Y}_{1,1}$ element is the first element of $Y$, and the $\mathbf{Y}_{2,1}$ element is the second element of $Y$ and so on. Once the input matrices are vectorized, standard gamma regression is performed.  
 
Let $Y_{i}$ be the dependent variable, produced by vectorizing a binary proximity matrix, for observation $i$. 
\begin{itemize} 
\item The Gamma distribution with scale parameter $\alpha$ has a \emph{stochastic component} given by  
\begin{eqnarray*} 
Y &\sim  \text{Gamma} ( y_{i} | \lambda_i, \alpha)\\ 
f(y) & = \frac{1}{\alpha^{\lambda_i}\Gamma \lambda_i} y_i^{\lambda_i - 1} \exp - \left[ \frac{y_i}{\alpha} \right] 
\end{eqnarray*} 
for $\alpha, \lambda_i, y_i > 0$. 
\item The \emph{systematic component} is given by: 
\begin{equation*} 
\lambda_{i} =  \frac{1}{x_{i}\beta}. 
\end{equation*} 
 
\end{itemize} 
 
 
\subsubsection{Quantities of Interest} 
The quantities of interest for the network gamma regression are the same as those for the standard gamma regression.  
\begin{itemize} 
\item The expected values ({\tt qi\$ev}) are simulations of the mean of the stochastic component given draws of $\alpha$ and $\beta$ from their posteriors:    
\begin{equation*} 
E(Y) = \alpha_i \lambda. 
\end{equation*} 
 
\item The predicted values ({\tt qi\$pr}) are draws from the gamma distribution for each set of parameters $(\alpha, \lambda_i)$.  
 
\item The first difference ({\tt qi\$fd}) for the network gamma model is defined as  
\begin{equation*} 
FD = \text{Pr}(Y | x_{1}) - \text{Pr}(Y | x) 
\end{equation*} 
\end{itemize} 
 
 
\subsubsection{Output Values} 
 
The output of each Zelig command contains useful information which you may view. For example, you run \verb{ z.out <- zelig(y ~ x, model = "gamma.net", data){, then you may examine the available information in {\tt z.out} by using {\tt names(z.out)}, see the coefficients by using {\tt z.out\$coefficients}, and a default summary of information through {\tt summary(z.out)}. Other elements available through the {\tt \$} operator are listed below.  
\begin{itemize} 
\item From the {\tt zelig()} output stored in {\tt  z.out}, you may extract: 
\begin{itemize} 
\item {\tt coefficients}: parameter estimates for the explanatory variables. 
\item {\tt fitted.values}: the vector of fitted values for the explanatory variables. 
\item {\tt residuals}: the working residuals in the final iteration of the IWLS fit.  
\item {\tt linear.predictors}: the vector of $x_{i}\beta$. 
\item {\tt aic}: Akaike\'s Information Criterion (minus twice the maximized log-likelihood plus twice the number of coefficients). 
\item {\tt bic}: the Bayesian Information Criterion (minus twice the maximized log-likelihood plus the number of coefficients times log $n$). 
\item {\tt df.residual}: the residual degrees of freedom. 
\item {\tt df.null}: the residual degrees of freedom for the null model.  
\item {\tt zelig.data}: the input data frame if {\tt save.data = TRUE}  
 
\end{itemize} 
\item From {\tt summary(z.out)}(as well as from {\tt zelig()}), you may extract: 
\begin{itemize} 
\item {\tt mod.coefficients}: the parameter estimates with their associated standard errors, $p$-values, and $t$ statistics.  
\item {\tt cov.scaled}: a $k \times k$ matrix of scaled covariances. 
\item {\tt cov.unscaled}: a $k \times k$ matrix of unscaled covariances.  
\end{itemize} 
\item From the {\tt sim()} output stored in {\tt s.out}, you may extract: 
\begin{itemize} 
\item {\tt qi\$ev}: the simulated expected probabilities for the specified values of {\tt x}. 
\item {\tt qi\$pr}: the simulated predicted values drawn from a distribution defined by $(\alpha_i, \lambda)$. 
\item {\tt qi\$fd}: the simulated first differences in the expected probabilities simulated from {\tt x} and {\tt x1}. 
\end{itemize} 
\end{itemize} 
 
 \subsection* {How to Cite} 

\input{cites/gamma.net}
\input{citeZelig}
\subsection* {See also}
The network gamma regression is part of the {\tt netglm} package by Skyler J. Cranmer and is built using some of the functionality of the  {\tt sna} package by Carter T. Butts \citep{ButCar01}.In addition, advanced users may wish to refer to {\tt help(gamma.net)}. Sample data are fictional. 
 
\bibliographystyle{asa}
\bibliography{gk,gkpubs}
<<afterpkgs, echo=FALSE>>=
 after<-search()
 torm<-setdiff(after,before)
 for (pkg in torm)
 detach(pos=match(pkg,search()))
@
\end{document} 
