xreg: Flexible maximum-likelihood-based regression function

Description Usage Arguments Author(s) Examples

View source: R/xreg_function.R

Description

Allows a list of formulas and fitting functions to be used for each type or set of data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
xreg(
  controlList,
  dataList,
  start_values = numeric(),
  fixed_values = numeric(),
  latent_classes = 0,
  latent_class_parameters = character(),
  latent_id_colname = character(),
  return_type = "fit",
  print_sum = F,
  ...
)

Arguments

controlList

one or more xregControl-objects (concatenated using c() ) to control maximum-likelihood estimation for different types or sets of data provided in dataList. Can alternatively provide a single formula or list of formulas, in which case an xregControl object will be generated on the fly. An xreg-object can be provided, in which case the xregControlList will be extracted. See examples

dataList

Named list of data.frames for which maximum sum-likelihood should be estimated. Names must correspond to names of xregControl objects. If no names are provided, order will be used to decide which xregControl-object to use.

start_values

Optional named list or vector of numeric start values, to override those provided in the xregControl obects. Previously estimated xreg-objects can be used, in which case fitted values will be extracted.

fixed_values

Optional named list or vector of numeric values that will be held as fixed, and will be available in the same way as the fitted parameters. An xreg-object can be used.

latent_classes

Optional integer parameter defining the number of latent classes to be fitted

latent_id_colname

Optional parameter defining the name of the id column defining the individuals (or groups) over which latent classes are to be fitted

return_type

Optional debug function. Default value, "fit", returns and xreg-object with fitted values. "df" returns the final data.frame of estimated values. "first" returns likelihood for providedd start values. "first_df" returns the initial data.frame with start_values. "predict" returns final data.frame. "precalc_df" returns data.frame prior to calculation of likelihood. Useful for debugging of likelihood-function.

print_sum

Optional argument to force continuous printing of the progress of fitting. Can be useful for debugging.

...

optional arguments to be forwarded to x_mle, optim, xregControl, etc.

latent_class_parameter

Optional character vector with names corresponding to the parameters that are to be varied in the latent classes (if latent_classes > 1)

Author(s)

Kim Rand

Examples

1
2
3
4
control_continuous <- xregControl(formulas = list(x ~ y * YVAR + z + ZVAR, value ~ INTERCEPT + x * XVAR), start_values = c(INTERCEPT = 0, XVAR = 1, YVAR = 1, ZVAR = 1), p_fun = cont_normal, name = "CONTINUOUS")
control_dichotomos <- xregControl(formulas = list(value ~ INTERCEPT2 + z * ZVAR), start_values = c(INTERCEPT2 = 0, ZVAR = 1), p_fun = dich_logistic, name = "DICHOTOMOUS")
joint_control <- c(control_continuous, control_dichotomous)
xreg(controlList = joint_control, dataList = list(CONTINUOUS = df1, DICHOTOMUS = df2))

intelligentaccident/xreg documentation built on Jan. 17, 2021, 7:38 a.m.