2012年6月7日 星期四

R 常態圖

x<-seq(-8,8,0.1)
y1<-dnorm(x,0,1)
x11()
plot(x,y1,type="l",lwd=2,col="blue")
y2<-dnorm(x,0,2)
lines(x,y2,type="l",lwd=2,col="red")
y3<-dnorm(x,0,3)
lines(x,y3,type="l",lwd=2,col="green")
legend("topright",c("sigma=1","sigma=2","sigma=3"),lty=c(1,1,1),col=c("blue","red","green"))




x<-seq(-4,4,0.1)
y<-dnorm(x,0,1)
plot(x,y,type="l",lwd=2,col="blue")
z<-1.96
x<-seq(-z,z,0.1)
y<-dnorm(x,0,1)
polygon(c(-z,x,z),c(0,y,0),col="gray")

x<-seq(-4,4,0.1)
y<-dnorm(x,0,1)
png(file = "output.png")
plot(x,y,type="l",lwd=2,col="blue")
x<-seq(-4,-z,0.01)
y<-dnorm(x,0,1)
polygon(c(-4,x,-z),c(0,y,0),col="gray")
text(-3,0.1,"alpha=0.05")

dev.off()








沒有留言:

張貼留言