# Some types of regression: Linear Regression, Logistic Regression, Polynomial
# Regression, Stepwise Regression, Ridge Regression, Lasso Regression, ElasticNet
# Regression
#' Create a Regression object
#' @importFrom assertthat assert_that
#' @param y.vector ; A numeric vector representing the response values of a relationship.
#' @param x.vector ; A numeric vector representing the explainatory values of a relationship.
#' @param is.sample ; A boolean indicating that src.vector is a sample, not a population.
#' @param type ; Type of regression. Supported is 'linear'.
#' @return regression ; The errors of the response values compared to the linear regression line.
#' @export
my.regression <- function(y.vector, x.vector, is.sample = TRUE, type = "linear") {
assert_that(is.numeric(y.vector))
assert_that(is.vector(y.vector))
assert_that(is.numeric(x.vector))
assert_that(is.vector(x.vector))
assert_that(length(y.vector) == length(x.vector))
assert_that(is.logical(is.sample))
assert_that(type %in% c("linear"))
dst.obj <- list(y = y.vector, x = x.vector, is.sample = is.sample)
class(dst.obj) <- c(paste0(type, "_regression"), "regression")
return(dst.obj)
}
#' Get the prediction formula for a for a regression.
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return function ; A function that gives the response values for a given explanatory variable.
# @export
my.regression.prediction.formula.default <- function(object) {
assert_that(inherits(object, "regression"))
"Not Implemented"
}
#' Get the Y-intercept for a regression.
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric ; A function that gives the response values for a given explanatory variable.
# @export
my.intercept.default <- function(object) {
assert_that(inherits(object, "regression"))
"Not Implemented"
}
#' Get the slope for a regression.
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric ; The slope of a given regression.
# @export
my.slope.default <- function(object) {
assert_that(inherits(object, "regression"))
"Not Implemented"
}
#' Get the covariance for a regression.
#' (Only useful for classifying a corelation/regression as positive/negative or no relationship.)
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric ; The covariance of a given regression.
# @export
my.covariance.default <- function(object) {
assert_that(inherits(object, "regression"))
"Not Implemented"
}
#' Calculate the errors of the Y values of a regression.
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric vector ; The errors of the response values compared to the regression line.
# @export
my.errors.default <- function(object) {
"Not Implemented"
}
#' Calculate the errors of the Y values of a regression.
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric vector ; The errors of the response values compared to the regression line.
#' @export
my.errors.regression <- function(object) {
assert_that(inherits(object, "regression"))
dst.prediction.fnctn <- my.regression.prediction.formula(object)
dst.predicted.values <- dst.prediction.fnctn(object$x)
return(object$y - dst.predicted.values)
}
#' Calculate the correlation of the regression.
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric ; The correlation of the response values compared to the regression line.
# @export
my.correlation.default <- function(object) {
assert_that(inherits(object, "regression"))
"Not Implemented"
}
#' Calculate the coefficient of determination of a regression (also called the R/correlation squared).
#' @importFrom assertthat assert_that
#' @param object ; A regression object.
#' @return numeric ; The coefficient of determination of the regression line.
# @export
my.coefficient.of.determination.default <- function(object) {
assert_that(inherits(object, "regression"))
"Not Implemented"
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.