[R] Error in "[<-"(`*tmp*`, i, value = numeric(0)) :
sandsky
realstone at hotmail.com
Fri Sep 12 23:50:04 CEST 2008
I use "while" loop but it produces an errro. I have no idea about this.
Error in "[<-"(`*tmp*`, i, value = numeric(0)) :
nothing to replace with
The problem description is
The likelihood includes two parameters to be estimated: lambda
(=beta0+beta1*x) and alpha. The algorithm for the estimation is as
following:
1) with alpha=0, estimate lambda (estimate beta0 and beta1 via GLM)
2) with lambda, estimate alpha via ML estimation
3) with updated alpha, replicate 1) and 2) until alpha is converged to a
value
My source code is
alpha=rep(1,100)
beta0=rep(0,100)
beta1=rep(0,100)
lambda1=rep(0,100)
lambda2=rep(0,100)
verpi=rep(0,100)
L=rep(0,100)
alpha[0]=1
i=1
while(i<=100){
repeat{
verpi[i]<-c(5^alpha[i-1],10^alpha[i-1]-5^alpha[i-1],14^alpha[i-1]-10^alpha[i-1],18^alpha[i-1]-14^alpha[i-1])
r<-c(1,0,0,1)
k<-c(3,2,2,2)
x<-c(0.5,0.5,1.0,1.0)
GLM_results <- glm(r/k ~ x, family=binomial(link='cloglog'),
offset=log(verpi[i]),weights=k)
beta0[i]<-GLM_results$coefficients[[1]]
beta1[i]<-GLM_results$coefficients[[2]]
lambda1[i]<-beta0[i]+beta1[i]*x[1]
lambda2[i]<-beta0[i]+beta1[i]*x[3]
L[i]<-function(a){
s1_f1<-(exp(-lambda1[i]*(0^a-0^a))-exp(-lambda1[i]*(5^a-0^a)))
s2_f2<-(exp(-lambda1[i]*(10^a)-lambda2[i]*(14^a-10^a+14^a-14^a))
-exp(-lambda1[i]*(10^a)-lambda2[i]*(14^a-10^a+18^a-14^a)))
logl<-log(s1_f1*s2_f2)
return(-logl)}
optim(1,L[i])
alpha[i]<-round(optim(1,L[i])$par,2)
if(alpha[i]<=alpha[i-1])
break}
i=i+1
}
Best regards,
Jin
--
View this message in context: http://www.nabble.com/Error-in-%22-%3C-%22%28%60*tmp*%60%2C-i%2C-value-%3D-numeric%280%29%29-%3A-tp19464723p19464723.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list