BLUP: Compute the joint mean, variance and covariance of any random...

Description Usage Arguments Details Value Author(s) Examples

View source: R/BLUP.R

Description

Compute the joint mean, variance and covariance of any random effects in a glmssn model conditional on the data. This assumes each random effect has a Gaussian distribution with mean zero and covariance matrix sigma^2 * Identity. We just plug in the REML estimate of sigma^2 from the fitted glmssn model object.

Usage

1
BLUP(model, RE = NULL)

Arguments

model

An object of class glmssn-class

RE

Names of random effects (RE), defaults to all REs in the glmssn object, if any

Details

Similar to BLUP in the regress package.

Value

Mean

A vector of means for each Random Effect

Variance

A vector of variances for each Random Effect

Covariance

A variance-covariance matrix for the Random Effects

Author(s)

David Clifford support@SpatialStreamNetworks.com

Examples

 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
library(SSN)
#for examples, copy MiddleFork04.ssn directory to R's temporary directory
copyLSN2temp()
# NOT RUN
# Create a SpatialStreamNetork object that also contains prediction sites
#mf04p <- importSSN(paste0(tempdir(),'/MiddleFork04.ssn'), 
#  predpts = "pred1km", o.write = TRUE)
#use mf04p SpatialStreamNetwork object, already created
data(mf04p)
#for examples only, make sure mf04p has the correct path
#if you use importSSN(), path will be correct
mf04p <- updatePath(mf04p, paste0(tempdir(),'/MiddleFork04.ssn'))

## NOT RUN Distance Matrix has already been created
## createDistMat(mf04)

# The models take a little time to fit, so they are NOT RUN 
# Uncomment the code to run them
# Alternatively, you can load the fitted models first to look at results
data(modelFits)

## Random effect model using STREAMNAME as our random effect
#fitRE <- glmssn(Summer_mn ~ ELEV_DEM + netID,
#    ssn.object = mf04, EstMeth = "REML", family = "Gaussian",
#    CorModels = c("STREAMNAME"))
#for examples only, make sure fitRE has the correct path
#if you use importSSN(), path will be correct
fitRE$ssn.object <- updatePath(fitRE$ssn.object, 
	paste0(tempdir(),'/MiddleFork04.ssn'))

summary(fitRE)
## random effects details
fitREBLUP <- BLUP(fitRE)
str(fitREBLUP)
fitREBLUP$Mean

## spatial stream model with a random effect
#fitSpRE1 <- glmssn(Summer_mn ~ ELEV_DEM + netID,
#    ssn.object = mf04, EstMeth = "REML", family = "Gaussian",
#    CorModels = c("STREAMNAME","Exponential.tailup"),
#    addfunccol = "afvArea")
#for examples only, make sure fitRE has the correct path
#if you use importSSN(), path will be correct
fitSpRE1$ssn.object <- updatePath(fitSpRE1$ssn.object, 
	paste0(tempdir(),'/MiddleFork04.ssn'))

fitRE1BLUP <- BLUP(fitSpRE1)
str(fitRE1BLUP)
fitRE1BLUP$Mean

SSN documentation built on March 13, 2020, 1:49 a.m.