log_lik.stanmstte: Pointwise log-likelihood matrix

Description Usage Arguments Value Examples

Description

For models fit using MCMC only, the log_lik method returns the S by N pointwise log-likelihood matrix, where S is the size of the posterior sample and N is the number of data points, or in the case of the stanmvreg method (when called on stan_jm and stan_mstte model objects) an S by Npat matrix where Npat is the number of individuals.

Usage

1
2
## S3 method for class 'stanmstte'
log_lik(object, newdata = NULL, ...)

Arguments

newdata

An optional data frame of new data (e.g. holdout data) to use when evaluating the log-likelihood. See the description of newdata for posterior_predict.

offset

A vector of offsets. Only required if newdata is specified and an offset was specified when fitting the model.

Value

For the stanreg and stanmvreg methods an S by N matrix, where S is the size of the posterior sample and N is the number of data points. For the stanjm and stanmstte method an S by Npat matrix where Npat is the number of individuals.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 roaches$roach100 <- roaches$roach1 / 100
 fit <- stan_glm(
    y ~ roach100 + treatment + senior,
    offset = log(exposure2),
    data = roaches,
    family = poisson(link = "log"),
    prior = normal(0, 2.5),
    prior_intercept = normal(0, 10),
    iter = 500 # to speed up example
 )
 ll <- log_lik(fit)
 dim(ll)
 all.equal(ncol(ll), nobs(fit))

 # using newdata argument
 nd <- roaches[1:2, ]
 nd$treatment[1:2] <- c(0, 1)
 ll2 <- log_lik(fit, newdata = nd, offset = c(0, 0))
 head(ll2)
 dim(ll2)
 all.equal(ncol(ll2), nrow(nd))

csetraynor/mstte documentation built on May 31, 2019, 4:54 a.m.