linear_regression: A custom function that calculates multiple linear regression

Description Usage Arguments Format Value Examples

View source: R/lm_hua_clean.R

Description

It returns a table of beta coefficients, standard error, t value, and p value as variables, and predictors as observations. It also prints out confidence intervals and descriptive univariate statistics.

Usage

1
linear_regression(predictor, outcome)

Arguments

predictor

the predictor variables, can consist of multiple variables. It has to be in nxm matrix format

outcome

the outcome variables. It has to be in nx1 matrix format

Format

A sample health dataset is included and loaded automatically when loading the package

death_rate

death rate, per 1,000 population

doctor_num

number of doctors, per 100,000 population

hos_num

number of hospital, per 100,000 population

capita_nuuanl_income

annual per capita income, in thousands of $

population_den

population density per square mile

Value

returns a table of beta, SE, t value, p value of the linear regression

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Y = matrix(c(5.6, 7.9, 10.8), ncol=1)
X = matrix(c(1, 2, 3), ncol=1)
linear_regression(X, Y)

Y = matrix(c(1714,1664,1760,1685,1693,1670,1764,1764,1792,1850,1735,1775),
ncol=1)
X = matrix(c(2.4,2.52,2.54,2.74,2.83,2.91,3,3,3.01,3.01,3.02,3.07), ncol=1)
linear_regression(X, Y)

Y = mydata$death_rate
X = cbind(mydata$doctor_num, mydata$hos_num, mydata$capita_nuuanl_income,
mydata$population_den)
linear_regression(X, Y)

huajiangyy/lm.hua documentation built on Dec. 20, 2021, 4:51 p.m.