#' Get the degrees of freedom of a sample or population.
#' @importFrom assertthat assert_that
#' @param src.vsctor ; A numeric vector to calculate the degrees of freedom over.
#' @param is.sample ; A boolean indicating that src.vector is a sample, not a population.
#' @param npe ; A numeric, how many parameters are estimated. For variance, we
#' estimate 1 parameter (the mean) from the data. In linear regression, we estimate
#' parameters from the data (slope and intercept).
#' @return numeric ; The degrees of freedom.
#' @export
my.degrees.of.freedom <- function(src.vsctor, is.sample = TRUE, npe = 1) {
assert_that(is.numeric(src.vsctor))
assert_that(is.vector(src.vsctor))
assert_that(is.logical(is.sample))
assert_that(is.numeric(npe))
return(length(src.vsctor) - ifelse(is.sample, npe, 0))
}
#' Calculate the errors from the mean.
#' @importFrom assertthat assert_that
#' @param object ; A numeric vector to calculate the erors for.
#' @return numeric vector ; The errors of the response values compared to the mean.
#' @export
my.errors.numeric <- function(object) {
assert_that(is.numeric(object))
assert_that(is.vector(object))
dst.mean <- my.arithmetic.mean(object)
return(object - dst.mean)
}
#' Calculate the sum of squared errors. This uses 'my.errors(object)'.
#' @param object ; An object to calculate the sum of squared errors for.
#' @return numeric ; The sum of squared errors.
#' @export
my.sum.of.squared.errors <- function(object) {
dst.errors <- my.errors(object)
return(sum(dst.errors^2))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.