On 13-05-13 3:58 AM, irene castro conde wrote:
Hello,
I'm using the function nlminb of the package stats inside a loop and when the number
of trials grows, R crashes and says "R
GUI front-end has stopped working". Could you help me with this problem? I have
try in versions 2.15.1,2.15.2 and 3.0.0.
This is a bug that has been reported before:
https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15244
but so far we don't have an example that is reproducible enough to track
it down.
Could you please make your code reproducible (e.g. call set.seed(1234)
at the beginning, or some other seed value) and shorter? Just pick out
the value of i that causes the crash, don't loop over 3000 different values.
Duncan Murdoch
sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: i386-w64-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=Galician_Spain.1252 LC_CTYPE=Galician_Spain.1252
[3] LC_MONETARY=Galician_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Galician_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
This is my code:
u<-runif(3000)
k=13
n=length(u)
prob=vector(length=n)
ro=vector(length=n)
beta1=vector(length=n)
g1=vector(length=n)
sb1=vector(length=n)
low=vector(length=n)
tlow=vector(length=n)
effects=vector(length=n)
vb1=vector(length=n)
AA=list()
BB=list()
nnI=list()
library(stats)
for (i in 1:n){
v=as.numeric(u<=u[i])
p=mean(v)
A=vector(length=k)
n1=n%/%k
A<-sapply(1:k,function(m) A<-sum(v[((m-1)*n1+1):(m*n1)]))
A[k]=sum(v[((k-1)*n1+1):n])
AA[[i]]<-A
B=c(rep(n1,k-1),length(v[((k-1)*n1+1):n]))
BB[[i]]<-B
l1=vector(length=(length(A)))
L1<-function(pe,rho){
for(j in 1:length(A)){
if(A[j]==0){l1[j]=0} else {l1[j]<-sum(log(pe+(-rho/(rho-1))*(0:(A[j]-1))))}
}
return(sum(l1))}
l2=vector(length=(length(B-A)))
L2<-function(pe,rho){
for(j in 1:length(B-A)){
if((B[j]-A[j])==0){l2[j]=0} else
{l2[j]<-sum(log(1-pe+(-rho/(rho-1))*(0:(B[j]-A[j]-1))))}
}
return(sum(l2))}
l3=vector(length=(length(B)))
L3<-function(pe,rho){
for(j in 1:length(A)){
if(B[j]==0){l1[j]=0} else {l3[j]<-sum(log(1+(-rho/(rho-1))*(0:(B[j]-1))))}
}
return(sum(l3))}
L<-function(pe,rho){
L<-L1(pe,rho)+L2(pe,rho)-L3(pe,rho)
return(L)
}
Max<- function(x){ -L(x[1], x[2])}
opt<-nlminb(c(0.01,0.01), Max,lower = rep(0.001,2), upper =
rep(0.999,2),control=list(rel.tol=1e-6))
prob[i]=opt$par[1]
ro[i]=opt$par[2]
}
Thanks,
Irene Castro Conde.
[[alternative HTML version deleted]]
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.