interactionDL: Factor regression model with interactions using the...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/interactionDL.R

Description

Perform a regression of y onto X and all 2 way interactions in X using the latent factor model introduced in Ferrari and Dunson (2020). This version uses the Dirichlet-Laplace shrinkage prior as in the original paper.

Usage

1
2
3
4
5
6
interactionDL(y, X, nrun, burn = 0, thin = 1, 
              delta_rw = 0.0526749, a = 1/2, k = NULL, 
              output = c("covMean", "covSamples", "factSamples", 
              "sigSamples", "coefSamples","errSamples"), 
              verbose = TRUE, dump = FALSE, filename = "samps.Rds", 
              buffer = 10000, adapt = "burn", augment = NULL)

Arguments

y

response vector.

X

predictor matrix (n x p).

nrun

number of iterations.

burn

burn-in period.

thin

thinning interval.

delta_rw

metropolis-hastings proposal variance.

a

shrinkage hyperparameter.

k

number of factors.

output

output type, a vector including some of: c("covMean", "covSamples", "factSamples", "sigSamples", "coefSamples", "numFactors", "errSamples").

verbose

logical. Show progress bar?

dump

logical. Save samples to a file during sampling?

filename

if dump: filename to address list of posterior samples

buffer

if dump: how often to save samples

adapt

logical or "burn". Adapt proposal variance in metropolis hastings step? if "burn", will adapt during burn in and not after.

augment

additional sampling steps as an expression

Value

some of:

covMean

X covariance posterior mean

omegaSamps

X covariance posterior samples

lambdaSamps

Posterior factor loadings samples (rotationally ambiguous)

etaSamps

Posterior factor samples (rotationally ambiguous)

sigmaSamps

Posterior marginal variance samples (see notation in Bhattacharya and Dunson (2011))

phiSamps

Posterior main effect coefficient samples in factor form (rotationally ambiguous)

PsiSamps

Posterior interaction effect coefficient samples in factor form (rotationally ambiguous)

interceptSamps

Posterior induced intercept samples

mainEffectSamps

Posterior induced main effect coefficient samples

interactionSamps

Posterior induced interaction coefficient samples

ssySamps

Posterior irreducible error samples

Author(s)

Evan Poworoznek

Federico Ferrari

References

Ferrari, Federico, and David B. Dunson. "Bayesian Factor Analysis for Inference on Interactions." arXiv preprint arXiv:1904.11603 (2019).

See Also

interactionMGSP

Examples

 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
k0 = 5
p = 20
n = 50

lambda = matrix(rnorm(p*k0, 0, 0.01), ncol = k0)
lambda[sample.int(p, 40, replace = TRUE) +
         p*(sample.int(k0, 40, replace = TRUE)-1)] = rnorm(40, 0, 1)
lambda[1:7, 1] = rnorm(7, 2, 0.5)
lambda[8:14, 2] = rnorm(7, -2, 0.5)
lambda[15:20, 3] = rnorm(6, 2, 0.5)
lambda[,4] = rnorm(p, 0, 0.5)
lambda[,5] = rnorm(p, 0, 0.5)
plotmat(varimax(lambda)[[1]])

X = matrix(rnorm(n*k0),n,k0)%*%t(lambda) + matrix(rnorm(n*p), n, p)

beta_true = numeric(p); beta_true[c(1,3,6,8,10,11)] =c(1,1,0.5,-1,-2,-0.5)
Omega_true = matrix(0,p,p)
Omega_true[1,2] = 1; Omega_true[5,2] = -1; Omega_true[10,8] = 1; 
Omega_true[11,5] = -2; Omega_true[1,1] = 0.5; 
Omega_true[2,3] = 0.5; 
Omega_true = Omega_true + t(Omega_true)
y = X%*%beta_true + diag(X%*%Omega_true%*%t(X)) +  rnorm(n,0.5)

intdl = interactionDL(y, X, 1000, 500, k = 5)

poworoznek/infinitefactor documentation built on April 7, 2020, 1:10 p.m.