lin_least_squares_train_test: lin_least_squares_train_test

Description Usage Arguments Details Value Examples

View source: R/lin_least_squares_train_test.R

Description

Performs linear regression using ordinary least squares (OLS) or weighted least squares (WLS), with either an intercept included or not, for only a portion of the total number of instances provided. The remaining instances are set aside for testing. This works with both simple and multiple linear regression. It calculates the beta coefficients of the least squares linear regression equation that is generated with the training set, and then it passes the testing set instances to generate predictions of that data which was previously unknown during the model training stage.

Usage

1
lin_least_squares_train_test(x, y, intercept = TRUE, weighted = FALSE, train_set_prop = 0.8)

Arguments

x

matrix, dataframe, or vector of all predictor/predictors and its/their respective values

y

vector of target values from the matrix of known predictor values

intercept

TRUE by default, it computes the beta coefficients with an intercept included; if it is set to FALSE, then no intercept is used

weighted

FALSE by default, it computes the beta coefficients using ordinary least squares (OLS); if it is set to TRUE, then the beta coefficients are calculated using weighted least squares (WLS)

train_set_prop

set to 0.8 by default, it randomly selects this proportion of instances from x and y, of identical indexes, to use for training the linear least squares model, and then it uses the remaining instances of x and y for testing the model

Details

works only with numeric data

Value

A list of objects, including calculations of the estimates for the beta coefficients for each predictor, along with residuals and model evaluation metrics for both the training and testing sets

Examples

1
2
3
4
5
6
7
# Example 1
x <- data.frame(matrix(sample(100000, 200*5, replace=TRUE), ncol = 5))
y <- sample(100, 200, replace=TRUE)
model_stats <- lin_least_squares_train_test(x, y)
model_stats$beta
model_stats$training_model_eval_metrics
model_stats$testing_model_eval_metrics

rguin26/HW4 documentation built on Dec. 22, 2021, 3:09 p.m.