Learn R Programming

iprior (version 0.6.5)

kernL: Load the kernel matrices of an I-prior model

Description

Prepare the kernel matrices according to a user available model options list. This is then passed to the iprior function for model fitting. Both formula and non-formula input are supported.

Usage

kernL(y, ..., model = list())

# S3 method for formula kernL(formula, data, model = 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.

formula

The formula to fit when using formula interface.

data

Data frame containing variables when using formula interface.

Value

A list of 11 items. Some of the more important ones are described below.

Y

The response variable.

x

The explanatory variables in list form. Each element of the list corresponds to each variable. If one.lam = TRUE was called, then you should see a single element in this list.

Hl

A list of the kernel matrices calculated from the explanatory variables according to the model options.

n, p, l, r, no.int, q

These are, respectively, the sample size, the number of explanatory variables, the number of unique scale parameters, the number of higher order terms, the number of interacting variables, and the number of kernel matrices.

The rest of the list are unimportant to the end-user, but they are passed to the EM routine via a call to iprior.

Details

When using non-formula to load the model, the explanatory variables can either be vectors, matrices or data frames. These need to be entered one by one in the function call, separated by commas. This is because each entry will have one scale parameter attached to it. Like the iprior function, grouping the scale parameters can only be done using non-formula input (see examples).

Sometimes, the model to be fitted can be quite complex and heavy for the EM algorithm. Loading the data into an ipriorKernel object does the heavy matrix matrix operations upfront, and passed on to the EM routine when iprior is called.

One advantage of having a saved ipriorKernel object is that we are able to use any R optimiser and maximise the log-likelihood of the I-prior model in conjunction with logLik or deviance functions.

Examples

Run this code
str(ToothGrowth)
mod <- kernL(y = ToothGrowth$len,
             supp = ToothGrowth$supp,
             dose = ToothGrowth$dose,
             model = list(interactions="1:2"))
mod
kernL(len ~ supp * dose, data = ToothGrowth)  # equivalent formula call
kernL(len ~ supp * dose, data = ToothGrowth,
      model = list(parsm = TRUE))  # non-parsimonious option

# Choosing different kernels
str(stackloss)
kernL(stack.loss ~ ., data = stackloss,
      model = list(kernel = "FBM"))  # all FBM
kernL(stack.loss ~ ., data = stackloss,
      model = list(kernel = c("Canonical", "FBM", "Canonical")))

# Specifying higher order terms
kernL(stack.loss ~ Air.Flow + I(Air.Flow^2) + ., data = stackloss,
      model = list(order = c("1", "1^2", "2", "3")))

# If all scale parameters are the same, then use one.lam = TRUE
kernL(stack.loss ~ ., data = stackloss, model = list(one.lam = TRUE))

# You can rename the variables too
kernL(stack.loss ~ ., data = stackloss,
      model = list(yname = "response", xname = c("air", "water", "acid")))

# Sometimes the print output is too long, can use str() options here
print(mod, strict.width = "cut", width = 50)

Run the code above in your browser using DataLab