Class Notes (786,419)
Canada (482,179)
Statistics (473)
STAT 331 (24)
Kun Liang (6)
Lecture

Stat331 R-Tutorial2.pdf

5 Pages
100 Views
Unlock Document

School
University of Waterloo
Department
Statistics
Course
STAT 331
Professor
Kun Liang
Semester
Fall

Description
> workdat > dim(workdat) [1] 100 6 > > head(workdat) headcirc length gestage birthwt momage toxemia 1 27 41 29 1360 37 0 2 29 40 31 1490 34 0 3 30 38 33 1490 32 0 4 28 38 31 1180 37 0 5 29 38 30 1200 29 1 6 23 32 25 680 19 0 > > X dim(X) [1] 100 3 > X dim(X) [1] 100 4 > > n p n [1] 100 > p [1] 3 > > Y > Ybar > ############################################################# > # Multiple Linear Regression Model using matrix operations > ############################################################# > > ############################################################# > # LSE > beta > beta [,1] 1 7.095759064 gestage 0.508047213 birthwt 0.004354053 toxemia -0.512827214 -1- > ############################################################# > # Hat matrix > H > # Idempotent > max(H %*% H - H) [1] 6.036838e-16 > > # symmetric > max(t(H)- H) [1] 6.175616e-16 > > Yhat > ############################################################# > # ANOVA > > SSE SSR SST > SSE+SSR [1] 634.75 > SST [1] 634.75 > > ############################################################# > # Estimate sigma^2 > > sigma2 sigma > ############################################################# > # Estimate V(beta) > > sigma2 * solve(t(X) %*% X) 1 gestage birthwt toxemia 1 3.2315416731 -1.362046e-01 5.931466e-04 3.224007e-01 gestage -0.1362045547 6.303684e-03 -3.876433e-05 -1.577471e-02 birthwt 0.0005931466 -3.876433e-05 4.611619e-07 9.527183e-05 toxemia 0.3224006970 -1.577471e-02 9.527183e-05 1.363869e-01 > > > > ############################################################# > # Fit a Multiple Linear Regression Model using lm() function -2- > ############################################################# > > fm tmp tmp Call: lm(formula = headcirc ~ gestage + birthwt + toxemia, data = workdat) Residuals: Min 1Q Median 3Q Max -1.8521 -0.6677 -0.1265 0.3910 8.2361 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 7.0957591 1.7976489 3.947 0.000151 *** gestage 0.5080472 0.0793957 6.399 5.71e-09 *** birthwt 0.0043541 0.0006791
More Less

Related notes for STAT 331

Log In


OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.

Submit