MSE_loc: Simple MSE function

Description Usage Arguments Value Examples

View source: R/MSE_loc.R

Description

This function computes the MSE (Mean Squared Error) of prediction associated to a vector of coefficients A used to predict a response variable Y by linear regression on X, with an intercept or not.

Usage

1
MSE_loc(Y = Y, X = X, A = A, intercept = TRUE)

Arguments

Y

the response variable (vector)

X

the dataset (matrix of covariates)

A

the vector of coefficients

intercept

(boolean) to add a column of 1 to X if A contains an intercept and X doesn't.

Value

the Mean Squared Error observed on X when using A coefficients to predict Y.

Examples

1
2
3
4
5
6
7
8
9
# dataset generation
base = mixture_generator(n = 15, p = 5, valid = 100, scale = TRUE)
X_appr = base$X_appr # learning sample
Y_appr = base$Y_appr # response variable
X_test = base$X_test # validation sample
Y_test = base$Y_test # response variable (validation sample)
A = lm(Y_appr ~ X_appr)$coefficients
MSE_loc(Y = Y_appr, X = X_appr, A = A) # MSE on the learning dataset
MSE_loc(Y = Y_test, X = X_test, A = A) # MSE on the validation sample

CorReg documentation built on Feb. 20, 2020, 5:07 p.m.