brief-R

# brief-R - attributes(model see attributes of the object...

This preview shows page 1. Sign up to view the full content.

A Brief R Introduction 1. Program Installation http://www.r-project.org/ 2. a good tutorial : An introduction to R (How to get this? Google it or visit the R homepage . . manuals. .; link from the course website) 3. Example #set correct directory setwd("D:/yufeng/elvis/teaching/STOR664/Program") fiber <- read.table("fiber2.dat") ## read data names(fiber) <- c("no","X1","X2","X3","X4") ## name each column attach(fiber) ## the database “fiber” is attached to R search path so ## that one can approach the variable just by its name X <- as.matrix(fiber) ## store the database as matrix type X <- X[,3:5] ## take column 3-5 t(X) ## transpose matrix xtx = t(X)%*%X ## multiplication of matrices and assign the result on xtx ## print the object solve(xtx) ## inverse the matrix ?solve ## get help page of the function (in this case, solve) help(solve) model <- lm(X1~X2+X4) ## fit linear model summary(model) ## show summary of the model anova(model) ## show the anova table
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: attributes(model) ## see attributes of the object plot(X1, model\$residuals) ## residual plot ### confidence interval for X1 xc <- t(matrix(ncol=4, nrow=3, c(75,70,45, 80,70,45, 80,75,42, 65,80,40))) ## get new data pts xc<-data.frame(xc[,c(1,3)]) ## take column 1 and 3, ## store it as database type xc names(xc) <- c("X2","X4") ## give names as same as original ## variables p <- predict(model, xc,se.fit=T) ## prediction ## confidence interval, one can use the similar approach for ## construction of simultaneous CI and PI. CI_each <- cbind(p\$fit - qt(1-0.05/2,model\$df.residual)*p\$se.fit, p\$fit + qt(1-0.05/2,model\$df.residual)*p\$se.fit) ## more on drawing a graph plot(X2, X1) title("plot X2 vs X1") ## put a title abline(h=80) ## put a horizontal line abline(v=80) ## put a vertical line abline(a=10,b=1,lty=3) ## put a line with intercept a, and slope b lines(c(65,80),c(90,120)) ## put a line from (65,90) to (80, 120)...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online