> par(mfrow=c(1,1))> x <- 0:6
> plot(x,factorial(x),type="s",main="factorial x",log="y")
> choose(8,3)
[1] 56
> plot(0:8,choose(8,0:8),type="s",main="binomial coefficients")
> x <- seq(-3,3,0.01)
> y <- exp(-abs(x))
> plot(x,y,type="l",main= "x")
> y <- exp(-abs(x)^2)
> plot(x,y,type="l",main= "x")
> y <- exp(-abs(x)^3)
> plot(x,y,type="l",main= "x^3")
> y <- exp(-abs(x)^8)
> plot(x,y,type="l",main= "x^8")
> pnorm(-1.25)
[1] 0.1056498
> x <- seq(-3,3,0.01)
> z <- seq(-3,-1.25,0.01)
> p <- dnorm(z)
> z <- c(z,-1.25,-3)
> p <- c(p,min(p),min(p))
> plot(x,dnorm(x),type="l",xaxt="n",ylab="probability density",xlab="height")
> axis(1,at=-3:3,labels=c("146","154","162","170","178","186","192"))
> polygon(z,p,col="green")
> z <- seq(1.875,3,0.01)
> p <- dnorm(z)
> z <- c(z,3,1.875)
> p <- c(p,min(p),min(p))
> plot(x,dnorm(x),type="l",xaxt="n",ylab="probability density",xlab="height")
> axis(1,at=-3:3,labels=c("146","154","162","170","178","186","192"))
> polygon(z,p,col="yellow")
> z <- seq(-0.635,1.25,0.01)
> p <- dnorm(z)
> z <- c(z,1.25,-0.635)
> p <- c(p,0,0)
> plot(x,dnorm(x),type="l",xaxt="n",ylab="probability density",xlab="height")
> axis(1,at=-3:3,labels=c("146","154","162","170","178","186","192"))
> polygon(z,p,col="red")
> polygon(z,p,col="pink")
> par(mfrow=c(1,1))
> hist(runif(10000)*10,main="")
> means <- numeric(10000)
> for (i in 1:10000){
+ means[i] <- mean(runif(5)*10)
+ }
> hist(means,ylim=c(0,1600),main="")
> par(mfrow=c(2,2))
> hist(sample(1:6,replace=T,10000),breaks=0.5:6.5,main="",xlab="one die")
> a <- sample(1:6,replace=T,10000)
> b <- sample(1:6,replace=T,10000)
> hist(a+b,breaks=1.5:12.5,main="", xlab="two dice")
> c <- sample(1:6,replace=T,10000)
> hist(a+b+c,breaks=2.5:18.5,main="", xlab="three dice")
> d <- sample(1:6,replace=T,10000)
> e <- sample(1:6,replace=T,10000)
> hist(a+b+c+d+e,breaks=4.5:30.5,main="", xlab="five dice")
> lines(seq(1,30,0.1),dnorm(seq(1,30,0.1),17.5937,3.837668)*10000)
> par(mfrow=c(2,2))
> curve(dnorm,-3,3,xlab="z",ylab="Probability density",main="Density")
> curve(pnorm,-3,3,xlab="z",ylab="Probability",main="Probability")
> curve(qnorm,0,1,xlab="p",ylab="Quantile (z)",main="Quantiles")
> y <- rnorm(1000)
> hist(y,xlab="z",ylab="frequency",main="Random numbers")
> yvals <- rnorm(100,24,4)
> ydevs <- rnorm(100,0,1)
> ydevs <- (ydevs-mean(ydevs))/sd(ydevs)
> windows(7,4)
> par(mfrow=c(1,2))
> x <- seq(0,30,.25)
> plot(x,pchisq(x,3,7.25),type="l",ylab="p(x)",xlab="x")
> plot(x,pchisq(x,5,10),type="l",ylab="p(x)",xlab="x")
> x <- seq(0.05,4,0.05)
> plot(x,df(x,2,18),type="l",ylab="f(x)",xlab="x")
> plot(x,df(x,6,18),type="l",ylab="f(x)",xlab="x")
> windows(7,7)
> par(mfrow=c(1,1))
> df <- seq(1,30,.1)
> plot(df,qf(.95,df,30),type="l",ylab="Critical F")
> lines(df,qf(.95,df,10),lty=2)
> x <- seq(0.01,3,0.01)
> plot(x,df(x,1,10),type="l",ylim=c(0,1),ylab="f(x)")
> lines(x,df(x,2,10),lty=6,col="red")
> lines(x,df(x,5,10),lty=2,col="green")
> lines(x,df(x,30,10),lty=3,col="blue")
> legend(2,0.9,c("1","2","5","30"),col=(1:4),lty=c(1,6,2,3),
+ title="numerator d.f.")
> plot(1:30,qt(0.975,1:30), ylim=c(0,12),type="l",
+ ylab="Students t value",xlab="d.f.",col="red")
> abline(h=2,lty=2,col="blue")
> xvs <- seq(-4,4,0.01)
> plot(xvs,dnorm(xvs),type="l",lty=2,
+ ylab="Probability density",xlab="Deviates")
> lines(xvs,dt(xvs,df=5),col="red")
> x <- seq(0.01,4,.01)
> par(mfrow=c(2,2))
> y <- dgamma(x,.5,.5)
> plot(x,y,type="l",col="red",main="alpha = 0.5")
> y <- dgamma(x,.8,.8)
> plot(x,y,type="l",col="red", main="alpha = 0.8")
> y <- dgamma(x,2,2)
> plot(x,y,type="l",col="red", main="alpha = 2")
> y <- dgamma(x,10,10)
> plot(x,y,type="l",col="red", main="alpha = 10")
> par(mfrow=c(2,2))
> x <- seq(0,1,0.01)
> fx <- dbeta(x,2,3)
> plot(x,fx,type="l",main="a=2 b=3",col="red")
> fx <- dbeta(x,0.5,2)
> plot(x,fx,type="l",main="a=0.5 b=2",col="red")
> fx <- dbeta(x,2,0.5)
> plot(x,fx,type="l",main="a=2 b=0.5",col="red")
> fx <- dbeta(x,0.5,0.5)
> fx <- dbeta(x,2,0.5)
> plot(x,fx,type="l",main="a=2 b=0.5",col="red")
> fx <- dbeta(x,0.5,0.5)
> plot(x,fx,type="l",main="a=0.5 b=0.5",col="red")
0 Comments