\HeaderA{moranTest.bma}{Moran's I test for spatial residual autocorrelation for models with largest posterior support}{moranTest.bma}
\keyword{utilities}{moranTest.bma}
\begin{Description}\relax
This function is a simple wrapper to calculate the Moran's I statistic for the 
\code{n} models with largest posterior support - in terms of posterior model probabilities -identified by the BMA routine \code{spatFilt.bms}. 
The null hypothesis of the Moran's I test
is that of no spatial autocorrelation. The test used is the lm.morantest. Type \code{?lm.morantest} for
further information.
Requires: \code{library(spdep)} in order to use function \code{lm.morantest}.
\end{Description}
\begin{Usage}
\begin{verbatim}
moranTest.bma(object, variants="single",W,nmodel=NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] a 'bma' / 'spatFilt' object (as e.g. resulting from \code{\LinkA{spatFilt.bms}{spatFilt.bms}}) 
\item[\code{variants}] default is 'single', if set to double the Moran's I test is also calculated for the
best models without including the eigenvectors.    Cf. section 'Details' for more options.
\item[\code{W}] a weight matrix in form of a 'listw' object. 
\item[\code{nmodel}] the number of models for which the Moran's I test is computed. Cannot exceed the number of models stored in \code{object}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Ad \code{variants}: \\
This allows for a direct comparison
of the degree of spatial autocorrelation for  \\
a) not (!) dealing with the spatial patterns  (standard OLS regression)  \\
b) modelling spatial correlation following the spatial filtering approach  \\
If there is no spatial autocorrelation present in case a) one might follow
the standard BMA estimation, i.e. use function \code{bms} instead to deal with uncertainty
stemming from the explanatory variables only.
\end{Details}
\begin{Value}
Each column presents the coefficents for the model indicated by its column name. The zero coefficients are the excluded covariates per model.
Note that the coefficients returned are only those of the best (100) models encountered by the \code{bma} object (cf. argument \code{nmodels} of \code{\LinkA{bms}{bms}}).

For aggregate coefficients please refer to \code{\LinkA{coef.bma}{coef.bma}}.
\end{Value}
\begin{Author}\relax
Martin Feldkircher
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{spatFilt.bms}{spatFilt.bms}} for creating bma objects.

Check \url{http://bms.zeugner.eu} for additional help.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

  #sample a bma object:
   data(dataBoston);data(boston.soi);data(WL.boston); 
   bma1=spatFilt.bms(X.data=dataBoston,WList=WL.boston,burn=1e04,iter=1e04,nmodel=100)
   mTest=moranTest.bma(bma1,variants="double",W=nb2listw(boston.soi))           

  
  #extract p-values
  pvalueMat=cbind(sapply(mTest$moran,function(x) x$p.value),sapply(mTest$moranEV,function(x) x$p.value))

  
  #compare boxplots
  Colours=c("#1B9E77", "#D95F02", "#7570B3", "#E7298A", "#66A61E" ,"#E6AB02", "#A6761D", "#666666")
  par(mfrow=c(1,2))
  boxplot(pvalueMat[,1],main="Box plot of p-values \n OLS-regression",xaxt="n",col=Colours[3],outline=FALSE,ylim=c(0,1))
  grid()
  boxplot(pvalueMat[,2],main="Box plot of p-values \n Eigenvector augmented regression",xaxt="n",col=Colours[3],outline=FALSE,ylim=c(0,1))
  grid()
  par(mfrow=c(1,1))

\end{ExampleCode}
\end{Examples}

