Linear Regression Analysis HUDM 5122: Introduction To R Johnny Wang
Linear Regression Analysis HUDM 5122: Introduction To R Johnny Wang
HUDM 5122
Introduction to R
Johnny Wang
Open R
Types of data in R:
▶ numeric: real numbers (like doubles)
▶ integer: integers
▶ character: holds non-numeric values (like strings)
▶ logical: holds true/false values (like booleans)
R Objects
Computations in R:
▶ Simple algebraic: +, −, ∗, /
▶ Matrix computations: element-by-element is simple algebraic,
matrix is % ∗ %
▶ Exponential/Log: exp(), log()
R Basic Math
We did not finish the R intro last time. Let’s load Auto.csv.
> Auto <- read.csv("Auto.csv",header=T,na.strings="?")
> Auto <- na.omit(Auto)
> attach(Auto)
> names(Auto)
> class(mpg)
> class(cylinders)
What happened?
A Bit More R
The console executes a single command right away
x⊤ ⊤
left Σ̂ = λxleft , Σ̂xright = λxright