Description Usage Arguments Details Value Author(s) References See Also Examples
Predicts data from a gjam object, including conditional and out-of-sample prediction.
1 2 |
output |
object of |
newdata |
a |
y2plot |
|
ylim |
vector of lower and upper bounds for prediction plot |
FULL |
will return full chains for predictions as |
If newdata
is not specified, the response is predicted from xdata
as an in-sample prediction. If newdata
is specified, prediction is either conditional or out-of-sample.
Conditional prediction on a new set of y
values is done if newdata
includes the matrix ycondData
, which holds columns to condition on. ycondData
must be a matrix
and have column names matching those in y
that it will replace. ycondData
must have at least one column, but fewer than ncol(y)
columns. Columns not included in ycondData
will be predicted conditionally.
Alternatively, the list newdata
can include a new version of xdata
for out-of-sample prediction. The version of xdata
passed in newdata
has the columns with the same names and variable types as xdata
passed to gjam
. Note that factor levels must also match those included when fitting the model. All columns in y
will be predicted out-of-sample.
For count composition data the effort (total count) is 1000.
Because there is no out-of-sample effort for 'CC'
data, values are predicted on the [0, 1] scale.
See examples below.
|
design matrix. |
|
|
|
predictive intervals, only generated if |
|
|
|
effort |
|
full prediction chains if |
James S Clark, jimclark@duke.edu
Clark, J.S., D. Nemergut, B. Seyednasrollah, P. Turner, and S. Zhang. 2016. Generalized joint attribute modeling for biodiversity analysis: Median-zero, multivariate, multifarious data. Ecological Monographs, 87, 34-56.
gjamSimData
simulates data
A more detailed vignette is can be obtained with:
web site 'http://sites.nicholas.duke.edu/clarklab/code/'.
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 | ## Not run:
S <- 5
f <- gjamSimData(n = 200, S = S, Q = 3, typeNames = 'CC')
ml <- list(ng = 50, burnin = 5, typeNames = f$typeNames, holdoutN = 10)
out <- gjam(f$formula, f$xdata, f$ydata, modelList = ml)
# predict data
par(mfrow=c(1,3),bty='n')
gjamPredict(out, y2plot = colnames(f$ydata)) #predict the data in-sample
title('full sample')
# out-of-sample prediction
xdata <- f$xdata[1:20,]
xdata[,3] <- mean(f$xdata[,3]) # mean for x[,3]
xdata[,2] <- seq(-2,2,length=20) # gradient x[,2]
newdata <- list(xdata = xdata, nsim = 50 )
p1 <- gjamPredict(out, newdata = newdata)
# plus/minus 1 prediction SE, default effort = 1000
x2 <- p1$x[,2]
ylim <- c(0, max(p1$sdList$yMu[,1] + p1$sdList$yPe[,1]))
plot(x2, p1$sdList$yMu[,1],type='l',lwd=2, ylim=ylim, xlab='x2',
ylab = 'Predicted')
lines(x2, p1$sdList$yMu[,1] + p1$sdList$yPe[,1], lty=2)
lines(x2, p1$sdList$yMu[,1] - p1$sdList$yPe[,1], lty=2)
# .95 prediction error
lines(x2, p1$piList$yLo[,1], lty=3)
lines(x2, p1$piList$yHi[,1], lty=3)
title('SE and prediction, Sp 1')
# conditional prediction
ydataCond <- out$inputs$y[,1,drop=FALSE]*0 #set first column to zero
newdata <- list(ydataCond = ydataCond, nsim=50)
p0 <- gjamPredict(output = out, newdata = newdata)
ydataCond <- ydataCond + 20 #first column is 20
newdata <- list(ydataCond = ydataCond, nsim=50)
p1 <- gjamPredict(output = out, newdata = newdata)
plot(out$inputs$y[,4],p0$sdList$yMu[,4], cex=.4,col='orange'); abline(0,1,lty=2)
points(out$inputs$y[,4],p1$sdList$yMu[,4], cex=.4,col='blue')
title('Cond. on 1st Sp')
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.