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.> 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]]
Hi Works for me without error. However are you sure your code does what you suppose it does? It does not return anything visible BB is list 3000x13 with all values same except last element in each node. AA is list 3000x13 with various values. ro is a vector with 2997 values 0.001 one value .999 and 2 values 0.008 I did not check values of other objects. Regards Petr> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of irene castro conde > Sent: Monday, May 13, 2013 9:59 AM > To: R-help at r-project.org > Subject: [R] help: R GUI front-end has stopped working > > 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. > > > 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 at 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.
Hi Try to make crashes reproducible. As I said it works on my machine without any problem. sessionInfo() R Under development (unstable) (2013-02-13 r61942) Platform: i386-w64-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Czech_Czech Republic.1250 LC_CTYPE=Czech_Czech Republic.1250 [3] LC_MONETARY=Czech_Czech Republic.1250 LC_NUMERIC=C [5] LC_TIME=Czech_Czech Republic.1250 attached base packages: [1] stats datasets utils grDevices graphics methods base other attached packages: [1] lattice_0.20-13 fun_0.1 Maybe you could use ?debug or similar means for tracing values and evaluating the way your code is working. Maybe others can give you better insight so I cc to list. Regards Petr From: irene castro conde [mailto:erea_cc@hotmail.com] Sent: Monday, May 13, 2013 10:49 AM To: PIKAL Petr Subject: RE: [R] help: R GUI front-end has stopped working Hi, Thanks for answering. Yes, it is an extract of my function, I have to optimizate the L function, which is an likelihood, to obtain a vector of ro and another of prob. I have just try again and R have crashed. What can be happend? because it crashes in my boss computer too. But the thing it is that it does not crash always but it does the most of the times. Specially with a big "n". Regards, Irene.> From: petr.pikal@precheza.cz<mailto:petr.pikal@precheza.cz> > To: erea_cc@hotmail.com<mailto:erea_cc@hotmail.com>; r-help@r-project.org<mailto:r-help@r-project.org> > Subject: RE: [R] help: R GUI front-end has stopped working > Date: Mon, 13 May 2013 08:33:32 +0000 > > Hi > > Works for me without error. However are you sure your code does what you suppose it does? > > It does not return anything visible > > BB is list 3000x13 with all values same except last element in each node. > AA is list 3000x13 with various values. > ro is a vector with 2997 values 0.001 one value .999 and 2 values 0.008 > > I did not check values of other objects. > > Regards > Petr > > > > -----Original Message----- > > From: r-help-bounces@r-project.org<mailto:r-help-bounces@r-project.org> [mailto:r-help-bounces@r- > > project.org<mailto:r-help-bounces@r-%0b%3e%20%3e%20project.org>] On Behalf Of irene castro conde > > Sent: Monday, May 13, 2013 9:59 AM > > To: R-help@r-project.org<mailto:R-help@r-project.org> > > Subject: [R] help: R GUI front-end has stopped working > > > > 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. > > > > > 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<mailto: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.[[alternative HTML version deleted]]
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 at 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. >