predict.FactorHet {FactorHet}R Documentation

Predict after using FactorHet

Description

Predicted values for choosing particular profiles based on FactorHet.

Usage

## S3 method for class 'FactorHet'
predict(
  object,
  newdata = NULL,
  type = "posterior",
  by_group = FALSE,
  return = "prediction",
  ...
)

Arguments

object

A model estimated using FactorHet or FactorHet_mbo.

newdata

A dataset on which to generate predictions. The default, NULL, uses the estimation data.

type

An argument that specifies how to deal with group-membership probabilities when making predictions. The default is "posterior" which use the posterior probabilities for each observation in the training data for weighting the groups. If "posterior_predictive" is used, the group membership probabilities implied by the moderators, i.e. \hat{\pi}_k(X_i), will be used. If an observation in newdata is not in the estimation data (i.e., its value of group) is not found, then "posterior_predictive", i.e. \hat{\pi}_k(X_i), is used.

by_group

A logical value as to whether the predictions should be returned for each group or whether a weighted averaged based on the group membership probabilities (specified by type) should be reported. The default is FALSE.

return

A character value that determines the type of prediction return. The default is "prediction" that returns the predicted probability. The option "detailed" returns a variety of additional information. This is mostly called internally for other functions such as AME or margeff_moderators.

...

Miscellaneous options used internally and not documented.

Value

Returns an estimate of the predicted probability of choosing a profile for each observation. "Arguments" outlines different behavior if certain options are chosen.

Examples

data(immigration)
set.seed(1)
# Fit a model once for simplicity
fit <- FactorHet(Chosen_Immigrant ~ Plans + Ed + Country,
 design = immigration, lambda = 1e-4,
 # Randomly initialize, do only one iteration for speed
 init = FactorHet_init(nrep = 1),
 control = FactorHet_control(init = 'random_member'),
 K = 2, group = ~ CaseID, task = ~ contest_no, 
 choice_order = ~ choice_id)
immigration$pred_FH <- predict(fit)  

[Package FactorHet version 1.0.0 Index]