| bsarBig | R Documentation |
This function fits a Bayesian spectral analysis regression model for Big data.
bsarBig(formula, nbasis, nint, mcmc = list(), prior = list(), verbose = FALSE)
formula |
an object of class “ |
nbasis |
number of cosine basis functions. |
nint |
number of grid points where the unknown function is evaluated for plotting. The default is 500. |
mcmc |
a list giving the MCMC parameters.
The list includes the following integers (with default values in parentheses):
|
prior |
a list giving the prior information. The list includes the following parameters
(default values specify the non-informative prior):
|
verbose |
a logical variable. If |
The MCMC samples of the parameters in the model are stored in the list mcmc.draws and
the posterior samples of the fitted values are stored in the list fit.draws.
The output list also includes the following objects:
post.est |
posterior estimates for all parameters in the model. |
call |
the matched call. |
mcmctime |
running time of Markov chain from |
bsar
# Ttrue function
ftrue <- function(x){
ft <- 7*exp(-3*x) + 2*exp(-70*(x-.6)^2) - 2 + 5*x
return(ft)
}
# Generate data
set.seed(1)
nobs <- 100000 # Number of observations
sigmat <- .5 # True sigma
nxgrid <- 500 # number of grid points: approximate likelihood & plots
xdata <- runif(nobs) # Generate x values
fobst <- ftrue(xdata) # True f at observations
ydata <- fobst + sigmat*rnorm(nobs)
# Compute grid on 0 to 1
xdelta <- 1/nxgrid
xgrid <- seq(xdelta/2, 1-xdelta/2, xdelta)
xgrid <- matrix(xgrid,nxgrid)
fxgridt <- ftrue(xgrid) # True f on xgrid
# Fit data
fout <- bsarBig(ydata ~ xdata, nbasis = 50, nint = nxgrid, verbose = TRUE)
# Plots
smcmc <- fout$mcmc$smcmc
t <- 1:smcmc
par(mfrow=c(2,2))
matplot(t, fout$mcmc.draws$theta, type = "l", main = "Theta", xlab = "Iteration", ylab = "Draw")
plot(t, fout$mcmc.draws$sigma, type = "l", main = "Sigma", xlab = "Iteration", ylab = "Draw")
matplot(t, fout$mcmc.draws$tau, type = "l", main = "Tau", xlab = "Iteration", ylab = "Draw")
matplot(t, fout$mcmc.draws$gamma, type = "l", main = "Gamma", xlab = "Iteration", ylab = "Draw")
dev.new()
matplot(fout$fit.draws$xgrid, cbind(fxgridt, fout$post.est$fhatm, fout$post.est$fhatq),
type = "l", main = "Regression Function", xlab = "X", ylab = "Y")
# Compute RMISE for regression function
sse <- (fout$post.est$fhatm - fxgridt)^2
rmise <- intgrat(sse, 1/nxgrid)
rmise <- sqrt(rmise)
rmise
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.