iprior {iprior} | R Documentation |
Fit an I-prior regression model
Description
A function to perform regression using I-priors. The I-prior model parameters may be estimated in a number of ways: direct minimisation of the marginal deviance, EM algorithm, fixed hyperparameters, or using a Nystrom kernel approximation.
Usage
## Default S3 method:
iprior(
y,
...,
kernel = "linear",
method = "direct",
control = list(),
interactions = NULL,
est.lambda = TRUE,
est.hurst = FALSE,
est.lengthscale = FALSE,
est.offset = FALSE,
est.psi = TRUE,
fixed.hyp = NULL,
lambda = 1,
psi = 1,
nystrom = FALSE,
nys.seed = NULL,
model = list(),
train.samp,
test.samp,
intercept
)
## S3 method for class 'formula'
iprior(
formula,
data,
kernel = "linear",
one.lam = FALSE,
method = "direct",
control = list(),
est.lambda = TRUE,
est.hurst = FALSE,
est.lengthscale = FALSE,
est.offset = FALSE,
est.psi = TRUE,
fixed.hyp = NULL,
lambda = 1,
psi = 1,
nystrom = FALSE,
nys.seed = NULL,
model = list(),
train.samp,
test.samp,
intercept,
...
)
## S3 method for class 'ipriorKernel'
iprior(object, method = "direct", control = list(), ...)
## S3 method for class 'ipriorMod'
iprior(object, method = NULL, control = list(), iter.update = 100, ...)
Arguments
y |
Vector of response variables |
... |
Only used when fitting using non-formula, enter the variables (vectors or matrices) separated by commas. |
kernel |
Character vector indicating the type of kernel for the variables. Available choices are:
The |
method |
The estimation method. One of:
|
control |
(Optional) A list of control options for the estimation procedure:
|
interactions |
Character vector to specify the interaction terms. When
using formulas, this is specified automatically, so is not required. Syntax
is |
est.lambda |
Logical. Estimate the scale parameters? Defaults to
|
est.hurst |
Logical. Estimate the Hurst coefficients for fBm kernels?
Defaults to |
est.lengthscale |
Logical. Estimate the lengthscales for SE kernels?
Defaults to |
est.offset |
Logical. Estimate the offsets for polynomial kernels?
Defaults to |
est.psi |
Logical. Estimate the error precision? Defaults to
|
fixed.hyp |
Logical. If |
lambda |
Initial/Default scale parameters. Relevant especially if
|
psi |
Initial/Default value for error precision. Relevant especially if
|
nystrom |
Either logical or an integer indicating the number of Nystrom
samples to take. Defaults to |
nys.seed |
The random seed for the Nystrom sampling. Defaults to
|
model |
DEPRECATED. |
train.samp |
(Optional) A vector indicating which of the data points should be used for training, and the remaining used for testing. |
test.samp |
(Optional) Similar to |
intercept |
Optional intercept term. |
formula |
The formula to fit when using formula interface. |
data |
Data frame containing variables when using formula interface. |
one.lam |
Logical. When using formula input, this is a convenient way of
letting the function know to treat all variables as a single variable (i.e.
shared scale parameter). Defaults to |
object |
An |
iter.update |
The number of iterations to perform when calling the
function on an |
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 estimation.
Value
An ipriorMod
object. Several accessor functions have been
written to obtain pertinent things from the ipriorMod
object. The
print()
and summary()
methods display the relevant model
information.
Methods (by class)
-
iprior(ipriorKernel)
: Takes in object of typeipriorKernel
, a loaded and prepared I-prior model, and proceeds to estimate it. -
iprior(ipriorMod)
: Re-run or continue running the EM algorithm from last attained parameter values in objectipriorMod
.
See Also
optim, update, check_theta, print, summary, plot, coef, sigma, fitted, predict, logLik, deviance.
Examples
# 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, ToothGrowth$supp, ToothGrowth$dose,
interactions = "1:2")
# Formula based model option one.lam = TRUE
# Sets a single scale parameter for all variables
modf <- iprior(stack.loss ~ ., data = stackloss, one.lam = TRUE)
modnf <- iprior(y = stackloss$stack.loss, X = stackloss[1:3])
all.equal(coef(modnf), coef(modnf)) # both models are equivalent
# Fit models using different kernels
dat <- gen_smooth(n = 100)
mod <- iprior(y ~ X, dat, kernel = "fbm") # Hurst = 0.5 (default)
mod <- iprior(y ~ X, dat, kernel = "poly3") # polynomial degree 3
# Fit models using various estimation methods
mod1 <- iprior(y ~ X, dat)
mod2 <- iprior(y ~ X, dat, method = "em")
mod3 <- iprior(y ~ X, dat, method = "canonical")
mod4 <- iprior(y ~ X, dat, method = "mixed")
mod5 <- iprior(y ~ X, dat, method = "fixed", lambda = coef(mod1)[1],
psi = coef(mod1)[2])
c(logLik(mod1), logLik(mod2), logLik(mod3), logLik(mod4),
logLik(mod5))
## Not run:
# For large data sets, it is worth trying the Nystrom method
mod <- iprior(y ~ X, gen_smooth(5000), kernel = "se", nystrom = 50,
est.lengthscale = TRUE) # a bit slow
plot_fitted(mod, ci = FALSE)
## End(Not run)