Learn R Programming

iprior (version 0.6.5)

iprior: Fit an I-prior regression model

Description

A function to perform linear regression using I-priors. The I-prior model is fitted via maximum likelihood using an EM algorithm.

Usage

# S3 method for default
iprior(y, ..., model = list(), control = list())

# S3 method for formula iprior(formula, data = parent.frame(), model = list(), control = list(), ...)

# S3 method for ipriorKernel iprior(object, control = list(), ...)

# S3 method for ipriorMod iprior(object, control = list(), ...)

Arguments

y

Vector of response variables.

...

Only used for when fitting using non-formula, enter the variables (vectors or matrices) separated by commas. No other options applicable here.

model

List of model options. Not used for ipriorKernel or ipriorModel objects. Available options are:

Hurst

Set the value of the Hurst coefficient for all FBM kernels used, rather than one by one. This is a value between 0 and 1, and defaults to 0.5.

order

Character vector of length equal to the number of explanatory variables used, indicating specification of higher order scale parameters. The syntax is "a^b", for parameter a raised to the power b. For regular order terms, then just input "a".

parsm

Logical, defaults to TRUE. Set to FALSE to assign one scale parameter for all kernel matrices.

one.lam

Logical, defaults to FALSE. Only relevant when using the formula call. Should all the variable share the same scale parameter?

rootkern

Logical, defaults to FALSE. Setting to TRUE is equivalent to Gaussian process regression.

These options are also available, but are only relevant when calling using non-formula:

xname

Character vector to set the name of the explanatory variables. This is also set to the object name by default.

interactions

Character vector to specify the interaction terms. When using formulas, this is specified automatically. Syntax is "a:b" to indicate variable a interacts with variable b.

control

(optional) A list of control options for the EM algorithm and output:

stop.crit.

The EM stopping criteria, which is the difference in succesive log-likelihood values. Defaults to 1e-7.

progress

Option for the reporting of the EM while the function is running. Choose from one of "lite" (default), "full" (log-likelihood and parameters trace), "predloglik" (log-likelihood trace only) or "none". Visit the Wiki page for more information.

report

The EM reports every report iterations. Defaults to 100.

silent

(logical) Should the EM report should be printed or not? This is the same as setting progress = "none".

lambda, psi, sigma

These are options to set the initial values of the parameters. For convenience, the user may choose to input one of psi or sigma, but not both, since psi = 1 / sigma ^ 2.

intercept

It is possible to set a fixed value for the intercept (not recommended).

formula

The formula to fit when using formula interface.

data

Data frame containing variables when using formula interface.

object

This is either an object of class formula (when fitting using formula interface), ipriorKernel or ipriorModel. This is used when not using formula or "y, x" input.

Value

An object of class ipriorMod which is a list of 24 items. The more important items are described below.

alpha, lambda, psi, coefficients, sigma

The last attained parameter values after running the EM algorithm. This can also be extracted via coef()

log.lik

The last attained log-likelihood value. This can also be extracted via logLik().

no.iter

The number of iterations the EM algorithm ran for.

Hlam.mat

This is the scaled kernel matrix of dimension n by n.

VarY.inv

The variance-covariance matrix of the marginal distribution of y.

w.hat

The vector of posterior mean estimates of the I-prior random effects.

fitted.values

These are posterior estimates of y, i.e. the fitted values. This can also be extracted via fitted() or predict()

residuals

The vector of residuals. This can also be extracted via resid().

Methods (by class)

  • ipriorKernel: Takes in object of type ipriorKernel and estimates the parameters of the model via the EM algorithm.

  • ipriorMod: Re-run or continue running the EM algorithm from last attained parameter values in object ipriorMod.

Details

The iprior() function is able to take formula based input and non-formula. When not using formula, the syntax is as per the default S3 method. That is, the response variable is the vector y, and any explanatory variables should follow this, and separated by commas.

As described here, the model can be loaded first into an ipriorKernel object, and then passed to the iprior() function to perform the EM algorithm.

If an ipriorMod object is input, then the EM starts from the last obtained parameter values. This is particularly useful for very heavy models, or models which have not yet converged after reaching the maximum number of iterations. Running iprior() just continues the EM algorithm.

There are several model options available which primarily controls the number and placement of scale parameters lambda in the model, although these are not applicable when running the function on ipriorMod or ipriorKernel objects.

Examples

Run this code
# Formula based input
(mod.stackf <- iprior(stack.loss ~ Air.Flow + Water.Temp + Acid.Conc.,
                      data = stackloss))
mod.toothf <- iprior(len ~ supp * dose, data = ToothGrowth)
summary(mod.toothf)

# Non-formula based input
mod.stacknf <- iprior(y = stackloss$stack.loss,
                      Air.Flow = stackloss$Air.Flow,
                      Water.Temp = stackloss$Water.Temp,
                      Acid.Conc. = stackloss$Acid.Conc.)
mod.toothnf <- iprior(y = ToothGrowth$len,
                      supp = ToothGrowth$supp,
                      dose = ToothGrowth$dose,
                      model = list(interactions = "1:2"))

# Formula based model option one.lam = TRUE
# Sets a single scale parameter for all variables
modf <- iprior(stack.loss ~ ., data = stackloss, model = list(one.lam = TRUE))
modnf <- iprior(y = stackloss$stack.loss, x = stackloss[1:3])

# Example of using the FBM kernel for smoothing models
mod <- kernL(y ~ x, datfbm, model = list(kernel = "FBM"))  # Hurst = 0.5 (default)
mod <- kernL(y ~ x, datfbm, model = list(kernel = "FBM,0.75"))  # custom Hurst

# Fit the model using EM starting at a specific parameter value
mod.fit <- iprior(mod, control = list(lambda = 8.41, psi = 0.33))

Run the code above in your browser using DataLab