TRMF_regression: Add external regressors to TRMF object

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

View source: R/TRMF.R

Description

A function to add external regressors to a TRMF object.

Usage

1
TRMF_regression(obj, Xreg, type = c("global", "columnwise"))

Arguments

obj

TRMF object created by create_TRMF()

Xreg

Vector or matrix of external regressors. If type = "columnwise", Xreg can be a matrix or array, but the first two dimensions must match those of the data matrix.

type

how are the regressors added to the model. If type = "global" the matrix factorization includes all the regressors. If type = "columnwise" each column in the data matrix is regressed of the corresponding column of Xreg.

Details

The coefficients model for the regressors are subject to the same regularization as the rest of the matrix factorization. Only one columnwise and one global model should be used in the same model. Both types can be include in the same model though.

Value

Returns an updated object of class TRMF.

Author(s)

Chad Hammerquist

See Also

create_TRMF, TRMF_columns, TRMF_trend

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
26
27
28
29
30
31
32
33
# ~ Global regression example ~
# create test data 
bb = (-10:10)/10
xReg = 10*cos(bb*10)
xm = poly(x = bb,degree=3)
fm = matrix(rnorm(40),4,10)
Am = cbind(xReg,xm)%*%fm+rnorm(210,0,.2)

# creat model and fit
obj = create_TRMF(Am)
obj = TRMF_trend(obj,numTS=3,order=2)
obj = TRMF_regression(obj,Xreg=xReg,type="global")
out = train(obj)
plot(out)

# ~ columnwise regression example ~
# create test data 
bb = (-10:10)/10
xm = poly(x = bb,degree=4)
fm = matrix(rnorm(84),4,21)
Am = xm%*%fm+rnorm(441,0,.2)

layers = array(0,dim=c(21,21,2))
layers[,,1] = 2*cos(2*bb)%o%sin(4*bb)
layers[,,2] = 2*sqrt(abs(bb%o%bb))
nAm = Am+layers[,,1]+layers[,,2]

# creat model and fit
obj = create_TRMF(nAm)
obj = TRMF_trend(obj,numTS=4,order=2)
obj = TRMF_regression(obj,Xreg=layers,type="columnwise")
out = train(obj)
plot(out)

TRMF documentation built on Aug. 16, 2021, 5:06 p.m.