Learn R Programming

analogue (version 0.4-0)

getK: Extract and set the number of analogues

Description

An extractor function to access the number of analogues used in particular models. Can also be used to set or update the stored value of $k$.

Usage

getK(object, ...)

## S3 method for class 'mat': getK(object, weighted = FALSE, ...)

## S3 method for class 'bootstrap.mat': getK(object, which = c("bootstrap", "model"), prediction = FALSE, ...)

getK(object, weighted = FALSE) <- value

## S3 method for class 'mat': getK(object, weighted = FALSE) <- value

Arguments

object
an R object; currently only for objects of class mat and class bootstrap.mat.
weighted
logical; extract/set number of analogues for a weighted or un-weighted model?
which
character; which k should be extracted, the one from the model or the one from the bootstrap results?
prediction
logical; should the extracted k be the one that is minimum for the test set (newdata) or the model (object).
...
further arguments to other methods.
value
integer; replacement value for $k$.

Value

  • For getK, an integer value that is the number of analogues stored for use. The returned object has attributes auto and weighted. auto refers to whether the extracted value of $k$ was set automatically (TRUE) or by the user (FALSE). weighted states if the returned value is for a weighted analysis or an un-weighted analysis (FALSE).

    For getK<-, the updated object.

Details

getK is a generic accessor function, and getK<- is a generic replacement function.

Objects of class bootstrap.mat contain several different k's. If no predictions are performed, there will be two k's, one for the model and one from bootstrapping the model. Where predictions are performed with newenv supplied, in addition to the k's above, there will be two k' for the predictions, one for the model-based and one for the bootstrap-based predictions. To select k for the predictions, use prediction = TRUE. Argument which determines whether the model-based or the bootstrap-based k is returned.

See Also

mat

Examples

Run this code
## continue the example from join
example(join)

## fit a MAT model
swap.mat <- mat(swapdiat, swappH, method = "SQchord")

## How many analogues gives lowest RMSE?
getK(swap.mat)
## note that this value was chosen automatically

## Now set k to be 10
getK(swap.mat) <- 10

## check
getK(swap.mat)

Run the code above in your browser using DataLab