#excercises from not to hand in homework: #generate a random normal variable x with mean= 2 and st.dev=1.5 of sample size 100 x=rnorm(100,mean=2,sd=1.5) #a histogram of x with 10 bins hist(x,nclass=10,main='Histogram of a normal r.v. with 100 samples',col='purple') #a histogram of x with 100 bins hist(x,nclass=100,main='Histogram of a normal r.v.',col='purple') #a histogram of x with 25 bins #after a little bit playing with number of bins #we can find the smoothest shape is presented with 25 bins hist(x,nclass=25,main='Histogram of a normal r.v. with 100 samples',col='purple') #generate a random normal variable y with mean= 2 and st.dev=1.5 of sample size 1000 y=rnorm(1000,mean=2,sd=1.5) #a histogram of y with 10 bins hist(y,nclass=10,main='Histogram of a normal r.v. with 1000 samples',col='green') #a histogram of y with 100 bins hist(y,nclass=100,main='Histogram of a normal r.v. with 1000 samples',col='green') #a histogram of y with 30 bins hist(y,nclass=30,main='Histogram of a normal r.v. with 100 samples',col='purple') #generate a random normal variable Z with mean= 2 and st.dev=1.5 of sample size 10000 z=rnorm(10000,mean=2,sd=1.5) #a histogram of Z with 10 bins hist(z,nclass=10,main='Histogram of a normal r.v. with 10000 samples',col='darkred') #a histogram of Z with 100 bins hist(z,nclass=100,main='Histogram of a normal r.v. with 10000 samples',col='darkred') #a histogram of Z with 30 bins hist(z,nclass=30,main='Histogram of a normal r.v. with 10000 samples',col='darkred') #Ch4, question 5 #use the probability transition matrix to get two steps ahead transition probability matrix P=matrix(c(1/2,1/3,1/6,0,1/3,2/3,1/2,0,1/2), ncol=3,byrow=T) P2=P%*%P P4=P2%*%P2 P8=P4%*%P4 #limiting probabilities: pi=c(0.4,0.2,0.4)