predict.sns {sns} | R Documentation |
Sample-based prediction using "sns" Objects
Description
Method for sample-based prediction using the output of sns.run
.
Usage
## S3 method for class 'sns'
predict(object, fpred
, nburnin = max(nrow(object)/2, attr(object, "nnr"))
, end = nrow(object), thin = 1, ...)
## S3 method for class 'predict.sns'
summary(object
, quantiles = c(0.025, 0.5, 0.975)
, ess.method = c("coda", "ise"), ...)
## S3 method for class 'summary.predict.sns'
print(x, ...)
Arguments
object |
Object of class "sns" (output of |
fpred |
Prediction function, accepting a single value for the state vector and producing a vector of outputs. |
nburnin |
Number of burn-in iterations discarded for sample-based prediction. |
end |
Last iteration used in sample-based prediction. |
thin |
One out of |
quantiles |
Values for which sample-based quantiles are calculated. |
ess.method |
Method used for calculating effective sample size. Default is to call |
x |
An object of class "summary.predict.sns". |
... |
Arguments passed to/from other functions. |
Value
predict.sns
produces a matrix with number of rows equal to the length of prediction vector produces by fpred
. Its numnber of columns is equal to the number of samples used within the user-specified range, and after thinning (if any). summary.predict.sns
produces sample-based prediction mean, standard deviation, quantiles, and effective sample size.
Note
See package vignette for more details on SNS theory, software, examples, and performance.
Author(s)
Alireza S. Mahani, Asad Hasan, Marshall Jiang, Mansour T.A. Sharabiani
References
Mahani A.S., Hasan A., Jiang M. & Sharabiani M.T.A. (2016). Stochastic Newton Sampler: The R Package sns. Journal of Statistical Software, Code Snippets, 74(2), 1-33. doi:10.18637/jss.v074.c02
See Also
Examples
## Not run:
# using RegressionFactory for generating log-likelihood and derivatives
library("RegressionFactory")
loglike.poisson <- function(beta, X, y) {
regfac.expand.1par(beta, X = X, y = y,
fbase1 = fbase1.poisson.log)
}
# simulating data
K <- 5
N <- 1000
X <- matrix(runif(N * K, -0.5, +0.5), ncol = K)
beta <- runif(K, -0.5, +0.5)
y <- rpois(N, exp(X %*% beta))
beta.init <- rep(0.0, K)
beta.smp <- sns.run(beta.init, loglike.poisson,
niter = 1000, nnr = 20, mh.diag = TRUE, X = X, y = y)
# prediction function for mean response
predmean.poisson <- function(beta, Xnew) exp(Xnew %*% beta)
ymean.new <- predict(beta.smp, predmean.poisson,
nburnin = 100, Xnew = X)
summary(ymean.new)
# (stochastic) prediction function for response
predsmp.poisson <- function(beta, Xnew)
rpois(nrow(Xnew), exp(Xnew %*% beta))
ysmp.new <- predict(beta.smp, predsmp.poisson
, nburnin = 100, Xnew = X)
summary(ysmp.new)
## End(Not run)