Description Usage Arguments Value Author(s) Examples
View source: R/CARrampsOcl.fit.R
This function fits CAR models to data. It draws independent samples from
the posterior distribution of precision parameters and regression coefficients
for certain polynomial trend surfaces. If the randeffs
argument is
set to true, it will also produce the estimated mean and standard
deviation of the marginal posterior density of each random effect.
1 2 |
alpha |
Vector of |
beta |
Vector of |
Q |
List of specifications of structure matrices for the CAR model.
Each element of the list Q is itself a list with 2 elements: \
|
y |
Vector of observed data values. If there is more than one structure matrix in the list called Q, then the data must be ordered accordingly. For example, suppose the data are measured on a rectangular lattice with r rows and c columns, and that Q[[1]] represents the within-row neighborhood structure while Q[[2]] represents the within-column neighborhood structure. Then the data must be in row-major order. |
nsamp |
Integer representing the number of desired draws from the joint posterior density of the model parameters. |
seed |
Seed for the random number generator. Must be a positive integer. |
fixed |
Logical value (TRUE or FALSE). CARrampsOcl.fit utilizes rejection sampling to draw from the marginalized joint
posterior density. This involves generating a batch of candidate values,
of which some are rejected and some are accepted. If |
coefs |
Logical value. If |
randeffs |
Logical. If true, random effects corresponding to each observation in the dataset will be calculated and returned. |
designMat |
The design matrix for regression. It must be set to NULL if
|
mult |
The |
filename |
The name for the file in which batches of accepted samples of precision parameters will be saved while the function is running. Future releases of the CARrampsOcl package will be able to use this output file to resume sampling after interruption. |
params |
Matrix of samples drawn from joint posterior density of the precision parameters. The first column is the measurement error precision, and subsequent columns are the spatial precisions in the same order as the Q matrices. |
phi |
List with two components: |
preds |
Always NULL in current release of CARramps. Future releases will enable estimation of means and standard deviations from posterior predictive distributions, which will be output here. |
regcoefs |
Matrix of samples drawn from joint posterior density of regression coefficients. There is one column for each coefficient. |
y |
Data vector |
acptrate |
Rejection sampling acceptance rate |
n |
Number of observations in |
Kate Cowles
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # load data
data(iowaSW06)
# construct random walk 2 structure matrix for each dimension
Q1<- makeRW2Q(33) # for rows
Q2<- makeRW2Q(24) # for columns
# dimensions of Q1, Q2, in that order
na<- nrow(Q1)
nb<- nrow(Q2)
Q <- list( list(type="Gen",content=Q1), list(type="Gen",content=Q2) )
# construct the design matrix with with as many columns as there are
# in null space of kronecker prod of Q's
X2 <- cbind( rep(1,nb), 1:nb)
X1 <- cbind( rep(1,na), 1:na)
X <- kronecker( X2, X1)
# parameters of gamma prior densities on tausqy, tausqphi[1], tausqphi[2]
alpha2 = beta2 <- c(.1, .1, .1)
# number of samples
nsamp = 100
#random seed
myseed = 314
output <- CARrampsOcl.fit(alpha=alpha2,
beta=beta2, Q=Q, y=iowaSW06, nsamp=nsamp,
seed=myseed,
fixed = FALSE, randeffs=TRUE, coefs=TRUE,designMat=X,
mult= 50)
# summarize marginal posterior densities of precision parameters
library(coda)
summary(as.mcmc( output$params ))
# summarize marginal posterior densities of regression coefficients
# intercept, slope within rows (west-to-east linear trend),
# slope for columns (north to south linear trend),
# interaction between rows and columns
summary(as.mcmc( output$regcoefs))
# summary statistics for site-specific random effects at first 10 sites
print( cbind( output$phi$phimean, output$phi$phisd)[1:10,] )
# plot the raw data and the posterior means of the site-specific random effects
plot2Q( output, numcols=32, col = rev(terrain.colors(32)),
rev.inds = c(FALSE, TRUE))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.