First time posting!
I'm trying to create a logit estimator using a looping simulation, where the loop detects the number of correct prediction (my code is below). Is it possible to change the shock in the distribution (defined as the standard deviation in the rnorm distribution) after a certain number of correct predictions? I'm trying it out with the f variable initialized below, but with little success. I was thinking that the f variable could change to 2 after a say 20 correct predictions, for example. The code below works -- with the hashes hiding a bit of working code -- but the results will not vary based on shock (the standard deviation is constant).
Thanks!
x<-1:7
y<-c(0,0,0,1,0,1,1)
n=2000
bin1<-rep(NA,n)
bin2<-rep(NA,n)
right<-NULL
b0<-rnorm(1,-4,.1)
b1<-rnorm(1,1,.1)
n=1000
ti=0
f<-1
iter<-0
bin1<-NULL
bin2<-NULL
right=-1
for (i in 1:n) {
nright<-NULL
nb0<-b0 + rnorm(1,0,1/f)
nb1<- b1+ rnorm(1,0,1/f)
predict<-((1/(1+exp(- nb0- nb1*x))))
for (j in 1:7) {
ifelse ( y[j]==1,nright[j]<-predict[j],nright[j]<-1-predict[j]) }
nright <- prod(nright)
if (nright>right) b0 <-nb0
if (nright>right) b1<- nb1
bin1[i]<-b0
bin2[i]<-b1
# ifelse ( nright > right, iter<-0, iter<-iter+1)
# if (iter > 50) f<- f/2
# if (f<.05) stop("Done")
if (nright>right) right<-nright
ti<-ti+1
}
f
ti
b0
b1