531f10MCIa

# 531f10MCIa - u=runif(10^4, min=-0.5, max=1) x=h(u)*1.5

This preview shows pages 1–2. Sign up to view the full content.

############################################################# # STAT 531 MCIa ############################################################# h=function(x){(cos(50*x)+sin(20*x))^2} par(mfrow=c(2,1)) curve(h,xlab="Function",ylab="",lwd=2) print(integrate(h,0,1)) u=runif(10^4) x=h(u) estint=cumsum(x)/(1:10^4) esterr=sqrt(cumsum((x-estint)^2))/(1:10^4) estint[10000] plot(estint, xlab="Mean and error range",type="l", lwd=2, ylim=mean(x)+20*c(- esterr[10^4],esterr[10^4]),ylab="") lines(estint+2*esterr,col="gold",lwd=2) lines(estint-2*esterr,col="gold",lwd=2) ############################################################# h=function(x){dnorm(x)} print(integrate(h,0,1)) u=runif(10^4) x=h(u) estint=cumsum(x)/(1:10^4) esterr=sqrt(cumsum((x-estint)^2))/(1:10^4) estint[10000] ############################################################# h=function(x){dnorm(x)} print(integrate(h,-0.5,1))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: u=runif(10^4, min=-0.5, max=1) x=h(u)*1.5 estint=cumsum(x)/(1:10^4) esterr=sqrt(cumsum((x-estint)^2))/(1:10^4) estint[10000] ############################################################# h=function(x){dnorm(x)} print(integrate(h,-100,1.28)) pnorm(1.28)-pnorm(-100) u=runif(10^4, min=-100, max=1.28) x=h(u)*101.28 estint=cumsum(x)/(1:10^4) esterr=sqrt(cumsum((x-estint)^2))/(1:10^4) estint[10000] ############################################################# x =rnorm(10^8) bound=qnorm(0.9) mean(x[1:10^8] < bound ) ############################################################# x =rnorm(10^8) bound=qnorm(c(.5, .75, .8, .9, .95, .99, .999, .9999)) res=matrix(0, ncol=8, nrow=7) for (i in 2:8) { for (j in 1:8) { res[i-1, j] =mean(x[1:10^i] < bound[j]) } } matrix(as.numeric(format(res, digi=4)), ncol=8)...
View Full Document

## This note was uploaded on 02/04/2011 for the course STAT 531 taught by Professor Gaborlukacs during the Spring '11 term at Manitoba.

### Page1 / 2

531f10MCIa - u=runif(10^4, min=-0.5, max=1) x=h(u)*1.5

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online