2+2 ?plot help(plot) ?par help(par) args(pnorm) q() qnorm(0.975) x <- 2 + 2 x <- 2 + 2 # The output should be 4! search() x <- 5:15 x[1] # Gives the first element of x. x[2:4] # Gives the elements x[2], x[3], x[4]. x[-(2:4)] # Gives all but x[2], x[3], x[4]. a1 <- c(1,3,5,6,8,21) a2 <- seq(1,21,by=2) a3 <-seq(min(weld$x),max(weld$x),length=100) a4 <-rep(2,12) y <- matrix(1:9, nrow=3) y[1, 2] y[1,] y[,2] # Gives the second column of y. z <- kyphosis ?kyphosis mean(weld$x) var(weld$x) weld$x*weld$y mean(weld$x*weld$y) weld$x^2 weld$x-1 wmx <- mean(weld$x) wxy <-weld$x*weld$y wxm1 <-weld$x-1 rm(a1) lm(y~x, data=weld) weld.lm1 <-lm(y~x, data=weld) resid(weld.lm1) coef(weld.lm1) plot(weld.lm1) deviance(weld.lm1) fitted(weld.lm1) print(weld.lm1) summary(weld.lm1) anova(weld.lm1) #We may be interested in whether a quadratic model fits the data any better. weld.lm2 <-lm(y ~ x + x^2, data=weld) weld.lm2 <- update(weld.lm1, .~. + x^2) plot(weld$x,weld$y) plot(weld$x,weld$y, xlab="Current", ylab="Diameter", las=1) x <- seq(min(weld$x),max(weld$x),length=100) y1 <- coef(weld.lm1)[1]+(coef(weld.lm1)[2]*x) lines(x,y1) y2 <- coef(weld.lm2)[1]+(coef(weld.lm2)[2]*x)+(coef(weld.lm2)[3]*x*x) lines(x,y2,lty=2) y1 <- predict(weld.lm1,data.frame(x)) y2 <- predict(weld.lm2,data.frame(x)) par(mfrow=c(1,1)) dput(y,"h:\\myfile.txt") z <- dget("h:\\myfile.txt")