predict.maxlogL {EstimationTools}R Documentation

Predict Method for maxlogL Fits

Description

[Maturing]

This function computes predictions and optionally the estimated standard errors of those predictions from a model fitted with maxlogLreg.

Usage

## S3 method for class 'maxlogL'
predict(
  object,
  parameter = NULL,
  newdata = NULL,
  type = c("link", "response", "terms"),
  se.fit = FALSE,
  terms = NULL,
  ...
)

Arguments

object

an object of maxlogL class generated by maxlogLreg function.

parameter

a character which specifies the parameter to predict.

newdata

a data frame with covariates with which to predict. It is an optional argument, if omitted, the fitted linear predictors or the (distribution) parameter predictions are used.

type

a character with the type of prediction required. The default (type = "link") is on the scale of the linear predictors; the alternative type = "response" is on the scale of the distribution parameter.

se.fit

logical switch indicating if standard errors of predictions are required.

terms

A character vector that specifies which terms are required if type = "terms". All terms are returned by default.

...

further arguments passed to or from other methods.

Details

This predict method computes predictions for values of any distribution parameter in link or original scale.

Value

If se.fit = FALSE, a vector of predictions is returned. For type = "terms", a matrix with a column per term and an attribute "constant" is returned.

If se.fit = TRUE, a list with the following components is obtained:

  1. fit: Predictions.

  2. se.fit: Estimated standard errors.

Note

Variables are first looked for in newdata argument and then searched in the usual way (which will include the environment of the formula used in the fit). A warning will be given if the variables found are not of the same length as those in newdata if it is supplied.

Author(s)

Jaime Mosquera GutiƩrrez, jmosquerag@unal.edu.co

Examples

library(EstimationTools)

#--------------------------------------------------------------------------------
# Example 1: Predictions from a model using a simulated normal distribution
n <- 1000
x <- runif(n = n, -5, 6)
y <- rnorm(n = n, mean = -2 + 3 * x, sd = exp(1 + 0.3* x))
norm_data <- data.frame(y = y, x = x)

# It does not matter the order of distribution parameters
formulas <- list(sd.fo = ~ x, mean.fo = ~ x)

norm_mod <- maxlogLreg(formulas, y_dist = y ~ dnorm, data = norm_data,
                       link = list(over = "sd", fun = "log_link"))
predict(norm_mod)


#--------------------------------------------------------------------------------
# Example 2: Predictions using new values for covariates
predict(norm_mod, newdata = data.frame(x=0:6))


#--------------------------------------------------------------------------------
# Example 3: Predictions for another parameter
predict(norm_mod, newdata = data.frame(x=0:6), param = "sd",
       type = "response")

#--------------------------------------------------------------------------------
# Example 4: Model terms
predict(norm_mod, param = "sd", type = "terms")


#--------------------------------------------------------------------------------

[Package EstimationTools version 4.0.0 Index]