predict.gsmf: Predict response with a generalized supervised MF model

Description Usage Arguments Examples

View source: R/gen_sup_mf.R

Description

Predict response with a generalized supervised MF model

Usage

1
2
3
## S3 method for class 'gsmf'
predict(object, newdata, type = c("link", "response", "PCs"),
  quiet = TRUE, max_iters = 1000, conv_criteria = 1e-05, start_A, ...)

Arguments

object

generalized supervised MF object

newdata

matrix of the same exponential family as covariates in object. If missing, will use the data that object was fit on

type

the type of fitting required. type = "link" gives response variable on the natural parameter scale, type = "response" gives response variable on the response scale, and type = "PCs" gives matrix of principal components of x

quiet

logical; whether the calculation should show progress

max_iters

maximum number of iterations

conv_criteria

convergence criteria

start_A

initial value for A

...

Additional arguments

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# construct a low rank matrices in the natural parameter space
rows = 100
cols = 10
set.seed(1)
loadings = rnorm(cols)
mat_np = outer(rnorm(rows), rnorm(cols))
mat_np_new = outer(rnorm(rows), loadings)

# generate a count matrices and binary responses
mat = matrix(rbinom(rows * cols, 1, c(inv.logit.mat(mat_np))), rows, cols)
mat_new = matrix(rbinom(rows * cols, 1, c(inv.logit.mat(mat_np_new))), rows, cols)

response = rbinom(rows, 1, rowSums(mat) / max(rowSums(mat)))
response_new = rbinom(rows, 1, rowSums(mat_new) / max(rowSums(mat_new)))

mod = genSupMF(mat, response, k = 2, alpha = 1000,
               family_x = "poisson", family_y = "binomial", quiet = FALSE)

plot(predict(mod, type = "response"), response)
plot(predict(mod, mat_new, type = "response"), response_new)

andland/genSupPCA documentation built on May 30, 2019, 11:43 a.m.