CAR.simLM: Simulate samples from a CAR model.

Description Usage Arguments Value Author(s) See Also Examples

View source: R/CAR.simLM.R

Description

This help page documents several functions for simulate samples from different CAR models.

Usage

1
2
3
4
5
CAR.simTorus(n1, n2, rho, prec)
CAR.simWmat(rho, prec, W)
CAR.simLM(pars, data)
CAR.simGLM(method = c("binom", "poisson"), W, n = NULL, pars, Xs = NULL,
n.trial = 1)

Arguments

n1, n2, n

n = c(n1, n2), the size of the torus

rho

the spatial coefficient in the CAR precision matrix (inverse of the covariance matrix)

prec

the precision in the CAR precision matrix

W

the spatial weight matrix

pars

parameter values of the direct CAR model

data

a data object same as described in loglik.dCAR

method

a character equal to either "binom" or "poisson" that indicate the distribution of the sample to be simulated.

Xs

the covariates to be used in the glm

n.trial

the number of trials in each unit of the binomial samples

Value

CAR.simTorus

returns a list containing the spatial weight matrix W and the simulated CAR samples X;

CAR.simWmat,CAR.simLM

returns an array of the simulated CAR samples;

CAR.simGLM

returns a list containing:

rho, sigma, beta,

the parameter values used to generate the samples

y,

the simulated data

covX,

the covariates

W,

the spatial weight matrix

Z.true,

the simulated CAR variables

eta,

the simulated glm linear response

Emean,

the simulated glm mean

n.trial,

the number of trials in each unit for binomial samples

Author(s)

Zhe Sha zhesha1006@gmail.com

See Also

mcl.glm, mcl.dCAR, mcl.prep.dCAR, mcl.prep.glm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Simulate CAR data on a torus
set.seed(33)
n.torus <- 10
rho <- 0.2
sigma <- 1.5
prec <- 1/sigma
beta <- c(1, 1)
XX <- cbind(rep(1, n.torus^2), sample(log(1:n.torus^2)/5))
mydata1 <- CAR.simTorus(n1 = n.torus, n2 = n.torus, rho = rho, prec = prec)

## Simulate CAR data for a given spatial weight matrix
Wmat <- mydata1$W
mydata2 <- CAR.simWmat(rho = rho, prec = prec, W = Wmat)

## Simualte data from a linear model with CAR error
y <- XX %*% beta + mydata1$X
mydata1$data.vec <- data.frame(y=y, XX[,-1])
mydata3 <- CAR.simLM(pars = c(0.1, 1, 2, 0.5), data = mydata1)

## Simulate Binomial data with CAR latent variables
mydata4 <- CAR.simGLM(method="binom", n=c(10,10), pars = c(rho, sigma,
                      beta), Xs=XX, n.trial = 5)

Example output



mclcar documentation built on Jan. 8, 2022, 5:07 p.m.