x<-seq(-5,5, by=0.1)
plot(x,dnorm(x,0,1),col="orange")
abline(v=1:dnorm(0,0,1),col="red",lty=2)
throw.coin<- function(){
x<- runif(1)
if(x<=1/2) 0 else 1
}
throw.coin()
# Tung dong xu n lan
Sample.coin<- function(n) replicate (n, throw.coin())
Sample.coin(20)
#Bang tan so 10,000 lan tung
X<- Sample.coin(10000)
table(X)
#Tan suat
table(X)/length(X)
1/2
#Tung con suc xac: lam tuong tu
throw.sucxac<- function(){
x<- runif(1)
if(x<=1/6) 1
else if (x<=2/6) 2
else if (x<= 3/6) 3
else if (x<= 4/6) 4
else if (x<= 5/6) 5
else 6
}
throw.sucxac()
#2.2. Cac phan phoi xac suat thong dung
#2.2.1
n<-10000
x<-rnorm(n)
y<-x^2
hist(y,freq=0,breaks=40)
hist(x,freq=0,breaks=40)
hist(y,freq=0,breaks=40)
curve(dchisq(x,df=1), col="red", add= TRUE)
hist(y,freq=0,breaks=40)
curve(dchisq(x,df=1))
#2.2.-2.2.4: SV tu nghien cuu lam tuong tu.
n<- 10000
m1<- 10
m2<- 20
sample.x <- rchisq(n, m1)
sample.y <- rchisq(n,m2)
hist(sample.x+sample.y,freq=0, breaks=40)
curve(dchisq(x,df=m1+m2), col="red",lty=1,lwd=2,add=TRUE)
#2.3
#2.3.1
mu<- 10
sigma=4
p<-0.99
a<-qnorm((1-p)/2,mean=mu,sd=sigma)
b<-qnorm((1+p)/2,mean=mu,sd=sigma)
khoang<-c(a,b)
khoang
#2.3