eda.shape <- function(x) { par(mfrow = c(2, 2)) hist(x) boxplot(x) iqd <- summary(x)[5] - summary(x)[2] plot(density(x,width=2*iqd), xlab = "x",ylab = "", type = "l") qqnorm(x) qqline(x) } eda.ts <- function(x) { par(mfrow=c(2,1)) ts.plot(x) acf(x) invisible() } x <- rnorm(100) eda.shape(x) eda.ts(x) library(MASS) cats male <- cats[cats$Sex=="M",]$Hwt female <- cats[cats$Sex=="F",]$Hwt eda.shape(male) t.test(male, mu=10) t.test(male, mu=10, conf.level=0.99) wilcox.test(male, mu=10) eda.shape(female) var.test(male,female) t.test(male,female,var.equal=T) t.test(male,female,var.equal=F) wilcox.test(male,female) x <- runif(20) y <- 2+3*x+rnorm(20) plot(x,y,main="X versus Y") cor.test(x,y) cor.test(x,y, alt="l") z1<-rnorm(50) z2<-rnorm(50) z3<-runif(50) par(mfrow=c(2,1)) plot.ecdf(z1,verticals=TRUE, col.p="white",col.v="black", main="Empirical CDF of z1 and z2") plot(ecdf(z2),add=TRUE,verticals=TRUE,col.p="white",col.v="black",lty="dotted") plot.ecdf(z1,verticals=TRUE, col.p="white",col.v="black",main="Empirical CDF of z1 and z3") plot(ecdf(z3),add=TRUE,verticals=TRUE,col.p="white",col.v="black",lty="dotted") ks.test(z1,"pnorm") ks.test(z1,z2) ks.test(z1,z3) binom.test(226,500,p=0.5) binom.test(226,500,p=0.4) prop.test(266,500) x<-rnorm(100) y<-sum(x>0) binom.test(y,100) z<-rnorm(100) d<-x-z binom.test(sum(d>0),length(d)) x<-c(80,100) n<-c(200,150) prop.test(x,n) library("gmodels") library("faraway") attach(solder) names(solder) X<-table(Solder,Mask) X summary(X) cross<-xtabs(~Solder+Mask) cross CrossTable(cross) iqdata<-read.table("iqdata.txt") attach(iqdata) scorend <- iqdata$V2[V1=="nd"] scored <- iqdata$V2[V1=="d"] boxplot(scorend, scored, names=c("Non-depressed mothers","Depressed mothers")) par(mfrow=c(2,1)) hist(scorend, xlab="IQ of children from Non-depressed mothers") hist(scored, xlab="IQ of children from depressed mothers") qqnorm(scorend,main="") qqline(scorend) title(main="Normal Probability plot for IQ of children from Non-depressed mothers") qqnorm(scored,main="") qqline(scored) title(main="Normal Probability plot for IQ of children from depressed mothers") t.test(scorend,scored,var.equal=T) var.test(scorend,scored) var.test(scorend[scorend>50],scored[scored>50]) t.test(scorend[scorend>50],scored[scored>50],var.equal=T)