Description Usage Arguments Value Note Examples
Runs the MCMC for the function-on-scalars regression model based on an FDLM-type 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 4 5 6 7 8 9 10 11 |
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
|
computeDIC |
logical; if TRUE, compute the deviance information criterion |
A named list of the nsave
MCMC samples for the parameters named in mcmc_params
If nm
is large, then storing all posterior samples for Yhat
, which is nsave x n 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 | # Simulate some data:
sim_data = simulate_fosr(n = 100, m = 20, p_0 = 100, p_1 = 5)
# Data:
Y = sim_data$Y; X = sim_data$X; tau = sim_data$tau
# Dimensions:
n = nrow(Y); m = ncol(Y); p = ncol(X)
# Run the FOSR:
out = fosr(Y = Y, tau = tau, X = X, K = 6, mcmc_params = list("fk", "alpha", "Yhat"))
# Plot a posterior summary of a regression function, say j = 3:
j = 3; post_alpha_tilde_j = get_post_alpha_tilde(out$fk, out$alpha[,j,])
plot_curve(post_alpha_tilde_j, tau = tau)
# Add the true curve:
lines(tau, sim_data$alpha_tilde_true[,j], lwd=6, col='green', lty=6)
# Plot the loading curves:
plot_flc(out$fk, tau = tau)
# Plot the fitted values for a random subject:
i = sample(1:n, 1)
plot_fitted(y = Y[i,], mu = colMeans(out$Yhat[,i,]),
postY = out$Yhat[,i,], y_true = sim_data$Y_true[i,], t01 = tau)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.