{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

531f10NR

# 531f10NR - STAT 531 NR cau = function(x,theta...

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

Sheet1 Page 1 ############################################################# # STAT 531 NR ############################################################# cau = function(x,theta) dcauchy(x,location=0, scale=theta) curve(cau(x,0.5),-4,4, col="orange", type="l",xlab="x",ylab="p(x)") curve(cau(x, 1), -4,4, col="red", type="l",xlab="x",ylab=" ", add=T) curve(cau(x, 2), -4,4, col="blue", type="l",xlab="x",ylab=" ", add=T) ############################################################# ref=rcauchy(400) f=function(theta){-sum(log(1+(x-theta)^2))} mi=NULL for (i in 1:400){ x=ref[1:i] aut=optimise(f,interval=c(-10,10), maximum=T) mi=c(mi,aut\$max) } plot(mi,ty="l",lwd=2,xlab="",ylab="arg") f=function(theta) {prod(1/(1+(x-theta)^2))} mip=NULL for (i in 1:400){ x=ref[1:i] aut=optimise(f,interval=c(-10,10), maximum=T) mip=c(mip,aut\$max) } lines(mip, col="sienna",lwd=2) ############################################################# newton=function(initial.value, num.its) { x=rep(0,10) x[1]=initial.value for (i in 2:10) { h=(1+1/x[i-1]-log(x[i-1]))*(1+x[i-1])/ (3+4/x[i-1]+1/x[i-1]^2-2*log(x[i-1])) x[i]=x[i-1]+h } out=cbind(1:num.its, x) dimnames(out)[[2]]=c("iteration","estimate") return(out) } newton(3,10) ############################################################# loglik <- function(p,y,n) lchoose(n,y)+y*log(p)+(n-y)*log(1-p) f <- function(x) -loglik(x,10,25)

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.

{[ snackBarMessage ]}

### Page1 / 2

531f10NR - STAT 531 NR cau = function(x,theta...

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

View Full Document
Ask a homework question - tutors are online