Description Usage Arguments Author(s) Examples
View source: R/vbvs_concurrent.R
Implements variational bayes variable selection for the linear functional concurrent model
1 2 3 |
formula |
formula for desired regression. should have form |
id.var |
variable giving subject ID vector |
data |
optional data frame |
Kt |
number of spline basis functions for coefficients and FPCs |
Kp |
number of FPCs to estimate |
v0 |
tuning parameter; normal spike variance |
v1 |
tuning parameter; normal slab variance |
standardized |
logical; are covariates already standardized? |
t.min |
minimum value to be evaluated on the time domain (useful if data are sparse and / or irregular). if 'NULL', taken to be minium observed value. |
t.max |
maximum value to be evaluated on the time domain (useful if data are sparse and / or irregular). if 'NULL', taken to be minium observed value. |
Jeff Goldsmith jeff.goldsmith@columbia.edu
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ## Not run:
library(dplyr)
library(tidyr)
library(refund.shiny)
## set design elements
set.seed(1)
I = 100
p = 50
## coefficient functions
beta1 = function(t) { sin(2*t*pi) }
beta2 = function(t) { cos(2*t*pi) }
beta3 = function(t) { 1 }
## FPC basis functions
psi1 = function(t) { sin(2*t*pi) }
psi2 = function(t) { cos(2*t*pi) }
## generate subjects, observation times, and FPC scores
time.data = sapply(1:I, function(u) {
ji = sample(10:15, 1)
rbind(runif(ji, 0, 1) %>% sort,
rep(u, ji),
rep(rnorm(1, 0, 3), ji),
rep(rnorm(1, 0, 1), ji))
}) %>% unlist() %>% matrix(ncol = 4, byrow = TRUE)
colnames(time.data) = c("time", "subj", "c_i1", "c_i2")
time.data = as.data.frame(time.data)
## generate predictor data
predictor.data = matrix(rnorm(dim(time.data)[1] * p), dim(time.data)[1], p)
colnames(predictor.data) = paste0("Cov_", 1:p)
## combine and generate responses
concurrent.data = cbind(time.data, predictor.data)
concurrent.data =
mutate(concurrent.data,
Y = Cov_1 * beta1(time) + ## fixed effects
Cov_2 * beta2(time) +
Cov_3 * beta3(time) +
c_i1 * psi1(time) + ## pca effects
c_i2 * psi2(time) +
rnorm(dim(concurrent.data)[1])) ## measurement error
## fit model
pred.list = paste("Cov", 1:p, sep = "_")
formula = as.formula( paste("Y ~", paste(pred.list, collapse = "+"), "| time") )
fit.vb = vb_concurrent(formula, id.var = "subj", data = concurrent.data, standardized = TRUE,
t.min = 0, t.max = 1, Kp = 3)
fit.vbvs = vbvs_concurrent(formula, id.var = "subj", data = concurrent.data, standardized = TRUE,
t.min = 0, t.max = 1, Kp = 3)
## interactive plot for mean model
plot_shiny(fit.vb)
plot_shiny(fit.vbvs)
## interactive plot for fpca expansion of residuals
plot_shiny(fit.vbvs$fpca.obj)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.