Description Usage Arguments Value Note Examples
Runs the MCMC for the function-on-scalars regression model based on a reduced-rank expansion. Here we assume the factor regression has independent errors, which allows for subject-specific random effects, as well as some additional default conditions.
1 2 3 |
Y |
the |
tau |
the |
X |
the |
K |
the number of factors; if NULL, use SVD-based proportion of variability explained |
nsave |
number of MCMC iterations to record |
nburn |
number of MCMC iterations to discard (burin-in) |
nskip |
number of MCMC iterations to skip between saving iterations, i.e., save every (nskip + 1)th draw |
mcmc_params |
named list of parameters for which we store the MCMC output; must be one or more of
|
Con_mat |
a |
A named list of the nsave
MCMC samples for the parameters named in mcmc_params
If Tm
is large, then storing all posterior samples for Yhat
or Ypred
, which are nsave x T x m
, may be inefficient
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 | ## Not run:
# Simulate some data (w/ NAs):
sim_data = simulate_dfosr(T = 100, m = 20,
p_0 = 2, p_1 = 2,
use_dynamic_reg = FALSE,
prop_missing = 0.5)
Y = sim_data$Y; X = sim_data$X; tau = sim_data$tau
T = nrow(Y); m = ncol(Y); p = ncol(X) # Dimensions
# Run the MCMC w/ K = 6:
out = fosr(Y = Y, tau = tau, X = X, K = 6,
mcmc_params = list("beta", "fk", "alpha", "Yhat", "Ypred"))
# Plot a regression coefficient function (Note: these are non-dynamic)
j = 3 # choose a predictor
post_alpha_tilde_j = get_post_alpha_tilde(out$fk, out$alpha[,j,])
plot_curve(post_f = post_alpha_tilde_j,
tau = tau,
main = paste('Posterior Mean and Credible bands, j =',j))
# Add the true regression coefficient function:
lines(tau, sim_data$alpha_tilde_true[1,j,], lwd=8, col='black', lty=6)
# Plot the factors:
plot_factors(post_beta = out$beta)
# Plot the loading curves:
plot_flc(post_fk = out$fk, tau = tau)
# Plot a fitted value w/ posterior predictive credible intervals:
i = sample(1:T, 1); # Select a random time i
plot_fitted(y = Y[i,],
mu = colMeans(out$Yhat)[i,],
postY = out$Ypred[,i,],
y_true = sim_data$Y_true[i,],
t01 = tau)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.