This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| datapp <- read.csv("data_pib.csv",header=T) | |
| datap2 <- datapp[datapp$sex<99,] | |
| datap <- datap2[datap2$skin<99,] | |
| attach(datap) | |
| plot(age,skin) | |
| plot(length,skin) | |
| tumor.table <- table(skin,age) | |
| tumor.table | |
| ages <- as.real(colnames(tumor.table)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x <- c(1,2,3,4,5,15) | |
| y <- c(3.1,5.9,9.3,11.8,15.1,1) | |
| plot(x,y) | |
| res <- lm(y~x) | |
| summary(res) | |
| abline(res) | |
| res1 <- lm(y~x,subset=c(-6)) | |
| summary(res1) | |
| yhat.6.6 <- predict(res1,data.frame(x=15)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data1 <- read.csv("data_set_1.csv") | |
| library(MASS) | |
| library(car) | |
| data1a <- within(data1,Y2<-exp(Y)) | |
| res <- stepAIC(lm(Y~(X1+X2+X3+X4+X5+X6)^2+I(X1^2)+I(X2^2)+I(X3^2)+I(X4^2)+I(X5^2)+I(X6^2),data=data1),k=log(2010)) | |
| plot(res,1) | |
| data2 <- read.csv("data_set_2.csv") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x <- c(1,2,3,4,5,15) | |
| y <- c(3.1,5.9,9.3,11.8,15.1,1) | |
| plot(x,y) | |
| res <- lm(y~x) | |
| summary(res) | |
| abline(res) | |
| res1 <- lm(y~x,subset=c(-6)) | |
| summary(res1) | |
| yhat.6.6 <- predict(res1,data.frame(x=15)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data <- read.csv("manhours.csv",header=T) | |
| library(MASS) | |
| library(car) | |
| library(leaps) | |
| attach(data) | |
| pairs(data) | |
| # The data concern the manpower and workload for US Navy Bachelor Officers' Quarters | |
| # Estimate manpower needs for manning Bachelor Officers Quarters. | |
| # Site: Site id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data <- read.csv("salary.csv") | |
| attach(data) | |
| # Analysis | |
| # | |
| # Different intercept, same slope | |
| res1 <- lm(Salary~YSdeg+Sex) | |
| summary(res1) | |
| # Different slope, same intercept | |
| res2 <- lm(Salary~YSdeg+Sex:YSdeg) | |
| summary(res2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Modeling Interactions | |
| # | |
| library(faraway) | |
| data(savings) | |
| attach(savings) | |
| summary(lm(sr~pop15+ddpi)) | |
| summary(lm(sr~pop15:ddpi)) | |
| summary(lm(sr~pop15+ddpi+pop15:ddpi)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # To add better variable names to data read in from a text file | |
| # The names are assigned in numerical order | |
| # | |
| data <- read.table("CH06PR18.txt") | |
| names(data) <- c("rental.rate","age","exp.tax","vacancy","sq.foot") | |
| # | |
| # To drop the 13 and 73 observation from a regression | |
| # | |
| res <- lm(Y~X1+X2+X3,subset=-c(13,73)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(faraway) | |
| data(savings) | |
| attach(savings) | |
| summary(savings) | |
| help(savings) | |
| pairs(savings) | |
| # | |
| # A better 'pairs' plot | |
| #res <- lm(sr~pop15) | |
| summary(res) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # What Polynomial? | |
| # | |
| data <- read.csv("sparrow.csv") | |
| attach(data) | |
| plot(ppha,pairs,xlab="Pedestrians per ha per min",ylab="Breeding pairs per ha") | |
| res3 <- lm(pairs~ppha+I(ppha^2)+I(ppha^3)) | |
| summary(res3) | |
| res3b <- lm(pairs~poly(ppha,3)) |