Learn R Programming

miniLNM (version 0.1.0)

prepare_newdata: Design Matrix for a Model

Description

This is a helper function to form the design matrix for an LNM regression starting from a fitted model's formula object. It is an analog of model.matrix for the multiresponse setting.

Usage

prepare_newdata(fit, newdata = NULL)

Value

A matrix containing the design matrix that can be multiplied with the fitted Beta parameter to get fitted compositions.

Arguments

fit

An object of class lnm whose estimate slot contains the 'rstan' fitted logistic normal multinomial model.

newdata

A data.frame containing variables in the formula definition of the fit, but which hasn't been converted into the matrix format needed for internal prediction.

Examples

Run this code
example_data <- lnm_data(N = 10, K = 5)
xy <- dplyr::bind_cols(example_data[c("X", "y")])
fit <- lnm(
    starts_with("y") ~ starts_with("x"), xy,
    iter = 5, output_samples = 5
)
prepare_newdata(fit, example_data[["X"]])

Run the code above in your browser using DataLab