## Read data x0<-c(1, 3, 5, 6) x0 x1<-c(rep(x0, 2)) x1 x<-c(rep(1, 3), rep(2, 4)) x m<-matrix(6, 3, 2 ) m m<-matrix(x1, 4, 2) m m<-matrix(x1, 2, 4) m table<-read.table("file.dat", header=Ture ) # sample from a finite population: roll a die or toss a coin x0<-c(1:6) # coin c(0, 1) x0 sizen<-5 x<-sample(x0, sizen) # sample size is 5. x ## Create random data from Normal population N(5, 1) x.norm <- rnorm(n=100, m=5, sd=1) summary(x.norm) par(mfrow=c(2,2)) ## Graphics display: two by two hist(x.norm, main="Histogram") ## Histogram boxplot(x.norm, main="Boxplot") # Boxplot qqnorm(x.norm) # QQ plot abline(mean(x.norm), sd(x.norm) ) # Add a straight line: y = a + b*x z.norm <- (x.norm - mean(x.norm))/sd(x.norm) # standardization qqnorm(z.norm) ## QQ-plot of z.norm abline(0, 1) ## Example 5.2.4, order statistics x<-c(56, 70, 89, 94, 96, 101, rep(102, 3), 105, 106, 108, 110, 113, 116) x summary(x) # five number summary and mean par(mfrow=c(2,2)) hist(x, main="Histogram of the data") boxplot(x, main="Boxplot") qqnorm(x) x.st<- (x- mean(x))/sd(x) qqnorm(x.st) abline(0, 1) # Define a function F<-function(x) { x^2+x+3 } F(5) par(mfrow=c(2,2)) n=10 S=100 x<-mean(rnorm(n, 0, 1)) # runif(n), rchisq(n, df), rt(n, df) for (i in 1:(S-1)) { xbar<-mean(rnorm(n), 0, 1) x<-c(x, xbar) i=i+1 } hist(x, main="hist of xbar") boxplot(x, main="boxplot of xbar") qqnorm(x) abline(mean(x), sd(x)) n<-30 mu<-5 sigma<-1 alpha<-0.05 S<-1000 x<-rnorm(n, mu, sigma) # a sample from N(mu, sigma) z<-qnorm(1-alpha/2, 0, 1) # critical value CI.lower<-mean(x)-z*sigma/sqrt(n) # lower limit of confidence interval CI.upper<-mean(x)+z*sigma/sqrt(n) # upper limit of confidence interval v=(CI.lowermu) # if true mu is between the uppper and lower limits v sum(v) ************************************************************** Learning R in 15 minutes: http://www.math.uic.edu/~jyang06/stat401/handouts/handout3.pdf