knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(bis557)

Package summary

This package includes one dataset lm_patho, and two functions my_linear_model() and my_grad_descent(). The purpose of these two functions are solving linear regression problem with different methods.

data lm_patho

lm_patho is a dataset with one dependent variabl, and two correlated independent variables.

data("lm_patho")
lm_patho

linear_model() function

The estimated coefficients are calculated in linear algebra way:

$\hat{\beta} = (X^TX)^{-1}X^TY$

lm_grad_descent() function

The estimated coefficients are obtained by iterating optimization algorithm, and the precision can be regulated by the algorithm finishing criteria.

Perform linear regression with lm() function

fit_lm <- lm(Sepal.Length  ~ ., iris)
fit_lm$coefficients

Perform linear regression with my_linear_model() function

fit_linear_model <- my_linear_model(Sepal.Length ~ ., iris)
fit_linear_model$coefficients

Perform linear regression with my_grad_descent() function

fit_gd <- my_grad_descent(Sepal.Length ~ ., iris)
fit_gd$coefficients

Perform linear regression with lm() function with colinearity problem

fit_lm <- lm(y  ~ ., lm_patho)
fit_lm$coefficients

Perform linear regression with my_linear_model() function with colinearity problem

fit_linear_model <- my_linear_model(y  ~ ., lm_patho)
fit_linear_model$coefficients

Perform linear regression with my_grad_descent() function with colinearity problem

fit_gd <- my_grad_descent(y  ~ ., lm_patho)
fit_gd$coefficients


tqchen07/bis557 documentation built on Dec. 21, 2020, 3:06 a.m.