surrogate.residual: Surrogate Residuals for Replciations of Spatial Ordinal Data

View source: R/sur_residual.R

surrogate.residualR Documentation

Surrogate Residuals for Replciations of Spatial Ordinal Data

Description

surrogate.residual simulate the surrogate residual with the the given parameter value and covariate for model diagnostics.

Usage

surrogate.residual(
  response,
  covar,
  location,
  seed = NULL,
  midalpha,
  beta,
  sigma2,
  phi,
  burn.in = 20,
  output = TRUE
)

Arguments

response

a matrix of observation (row: spatial site and column: subject).

covar

regression (design) matrix, including intercepts.

location

a matrix contains spatial location of sites within each subject.

seed

seed input for simulation (default =NULL). Parameter values:

midalpha

cutoff for latent ordinal response.

beta

regression coefficient for covar.

sigma2

σ^2 for exponential covariance.

phi

spatial correlation for exponential covariance.

burn.in

burn-in length (i.e. declaring the initial sample).

output

logical flag indicates whether printing out result (default: TRUE).

Details

Given vector of observed responses, the design matrix, spatial location for sites and parameter value, raw surrogate residuals are simulated using an efficient Gibbs sampling, which can be used for model diagnostics. When the fitted model is correct, the raw surrogate residuals among subjects should follow multivariate normal with mean 0 and covariance Sigma. If the model is correct, residual plot should be close to a null plot or random scatter. For example, it can be used to check the potential missing in covariate, non-linearity of covariate and outliers. In particular for the example below, the residual plot shows that linearity of Xi is adequate for the model.

Value

surrogate.residual returns a (no. spatial site * no. subject) matrix contains raw surrogate residuals with element corresponds to the response matrix.

Examples

set.seed(1228)
n.subject <- 50
n.lat <- n.lon <- 10
n.site <- n.lat*n.lon

beta <- c(1,2,-1) # First 1 here is the intercept
midalpha <- c(1.15, 2.18) ; phi <- 0.6 ; sigma2 <- 0.7

true <- c(midalpha,beta,phi,sigma2)

Xi <- rnorm(n.subject,0,1) ; Xj <- rbinom(n.site,1,0.6)

 VV <- matrix(NA, nrow = n.subject*n.site, ncol = 3)

 for(i in 1:n.subject){ for(j in 1:n.site){
     VV[(i-1)*n.site+j,] <- c(1,Xi[i],Xj[j])
       }
 }

location <- cbind(rep(seq(1,n.lat,length=n.lat),n.lat),rep(1:n.lon, each=n.lon))
response <- sim.rord(n.subject, n.site, n.rep = 1,
midalpha, beta, phi, sigma2, covar=VV, location)[[1]]


# Example for linearity of covariate
sur.resid <- surrogate.residual(response, covar=VV, location, seed =1,
midalpha, beta, sigma2, phi,
burn.in=20, output = TRUE)

scatter.smooth(rep(Xi,each=n.site),c(sur.resid),
main="Surrogate residual against Xi", xlab="Xi", ylab="Surrogate residual",
lpars = list(col = "red", lwd = 3, lty = 2))

abline(h=0, col="blue")



clordr documentation built on March 25, 2022, 1:06 a.m.