Learn R Programming

rcppmlpackexamples (version 0.0.1)

linearRegression: Run a linear regression with optional ridge regression

Description

Run a linear regression (with optional ridge regression)

Usage

linearRegression(matX, vecY, lambda = 0, intercept = TRUE)

Value

A vector with fitted values

Arguments

matX

A matrix of explanatory variables (‘predictors’) in standard R format (i.e. ‘tall and skinny’ to be transposed internally to MLPACK format (i.e. ‘short and wide’).

vecY

A vector of dependent variables (‘responses’)

lambda

An optional ridge parameter, defaults to zero

intercept

An optional boolean switch about an intercept, default is true.

Details

This function performs a linear regression, and serves as a simple test case for accessing an MLPACK function.

Examples

Run this code
suppressMessages(library(utils))
data("trees", package="datasets")
X <- with(trees, cbind(log(Girth), log(Height)))
y <- with(trees, log(Volume))
lmfit <- lm(y ~ X)
# summary(fitted(lmfit))
mlfit <- linearRegression(X, y)
# summary(mlfit)
all.equal(unname(fitted(lmfit)),  as.vector(mlfit))

Run the code above in your browser using DataLab