dear list I am student M.S. statistics in department statistics . I am working in the function "nls" in the [R 2.3.1] with 246 data and want to fit the "exp" model to vectors( v and u ) but I have a problem to use it u 5.000000e-13 2.179057e+03 6.537171e+03 1.089529e+04 1.525340e+04 1.961151e+04 2.396963e+04 2.832774e+04 3.268586e+04 3.704397e+04 4.140209e+04 4.576020e+04 5.011831e+04 5.447643e+04 v 8.382562e-01 4.090868e+02 1.311053e+03 2.124143e+03 3.365494e+03 2.138903e+03 7.687774e+03 1.028396e+04 1.004186e+04 2.059798e+04 1.438464e+04 2.861373e+04 2.294919e+04 2.807701e+04 data1<-data.frame(u=u ,v=v) nls(v~c0+(ce*(1-exp((-u)/ae))),data=data1,start=list(c0=0,ce=1000,ae=3000)) Error in nls(v ~ c0 + (ce * (1 - exp((-u)/ae))), data = data1, start = list(c0 = 0, : step factor 0.000488281 reduced below 'minFactor' of 0.000976563 i dont know how to solve it, please help me . best regards Sadeghian --------------------------------- [[alternative HTML version deleted]]
You need better starting values: f <- function(x) { c0 <- x[1]; ce <- x[2]; ae <- x[3] sum((v - c0+(ce*(1-exp((-u)/ae))))^2) } g <- 4^(0:8) g <- c(-g, g) g <- expand.grid(c0 = g, ce = g, ae = g) start <- g[which.min(apply(g, 1, f)), ] nls(v ~ c0+(ce*(1-exp((-u)/ae))), data = data1, start = start) On 10/10/07, azadeh sadeghian <a.sadeghian1386 at yahoo.com> wrote:> dear list > I am student M.S. statistics in department statistics . I am working in the function "nls" in the [R 2.3.1] with 246 data and want to fit the "exp" model to vectors( v and u ) but I have > a problem to use it > u > 5.000000e-13 2.179057e+03 6.537171e+03 1.089529e+04 1.525340e+04 > 1.961151e+04 2.396963e+04 2.832774e+04 3.268586e+04 3.704397e+04 > 4.140209e+04 4.576020e+04 5.011831e+04 5.447643e+04 > v > 8.382562e-01 4.090868e+02 1.311053e+03 2.124143e+03 3.365494e+03 > 2.138903e+03 7.687774e+03 1.028396e+04 1.004186e+04 2.059798e+04 > 1.438464e+04 2.861373e+04 2.294919e+04 2.807701e+04 > data1<-data.frame(u=u ,v=v) > nls(v~c0+(ce*(1-exp((-u)/ae))),data=data1,start=list(c0=0,ce=1000,ae=3000)) > Error in nls(v ~ c0 + (ce * (1 - exp((-u)/ae))), data = data1, start = list(c0 = 0, : > step factor 0.000488281 reduced below 'minFactor' of 0.000976563 > i dont know how to solve it, please help me . > best regards > Sadeghian > > > > > --------------------------------- > > [[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. >
azadeh sadeghian <a.sadeghian1386 <at> yahoo.com> writes:> > I am student M.S. statistics in department statistics . I am working in thefunction "nls" in the [R 2.3.1] You should update to a more recent version of R (2.6.0 is current)> with 246 data and want to fit the "exp" model to vectors( v and u ) but I have > a problem to use itYou note 246 data, but I count much less> u > 5.000000e-13 2.179057e+03 6.537171e+03 1.089529e+04 1.525340e+04 > 1.961151e+04 2.396963e+04 2.832774e+04 3.268586e+04 3.704397e+04 > 4.140209e+04 4.576020e+04 5.011831e+04 5.447643e+04 > v > 8.382562e-01 4.090868e+02 1.311053e+03 2.124143e+03 3.365494e+03 > 2.138903e+03 7.687774e+03 1.028396e+04 1.004186e+04 2.059798e+04 > 1.438464e+04 2.861373e+04 2.294919e+04 2.807701e+04 > data1<-data.frame(u=u ,v=v) > nls(v~c0+(ce*(1-exp((-u)/ae))),data=data1,start=list(c0=0,ce=1000,ae=3000)) > Error in nls(v ~ c0 + (ce * (1 - exp((-u)/ae))), data = data1, start = list(c0= 0, :> step factor 0.000488281 reduced below 'minFactor' of 0.000976563To find out what was wrong, plot your data and your start value fit. You can see that the start values are far off. But, more importantly, note that you data go up exponential-like and don't level off, while you model function does. So even if you find better start values, you result may be unreasonable: how should the poor fitting function know when to bend down? This might be caused by the subset of the 246 data points you presented here. Dieter u = c( 5.000000e-13, 2.179057e+03, 6.537171e+03, 1.089529e+04, 1.525340e+04, 1.961151e+04, 2.396963e+04, 2.832774e+04, 3.268586e+04, 3.704397e+04, 4.140209e+04, 4.576020e+04, 5.011831e+04, 5.447643e+04) v = c( 8.382562e-01, 4.090868e+02, 1.311053e+03, 2.124143e+03, 3.365494e+03, 2.138903e+03, 7.687774e+03, 1.028396e+04, 1.004186e+04, 2.059798e+04, 1.438464e+04, 2.861373e+04, 2.294919e+04, 2.807701e+04) data1 = data.frame(u=u ,v=v) start=list(c0=0,ce=1000,ae=3000) v1= with(start,c0+(ce*(1-exp((-u)/ae)))) plot(u,v) lines(u,v1) v1= nls(v~c0+(ce*(1-exp((-u)/ae))),data=data1,start=start,trace=TRUE)
dear list I am student M.S. statistics in department statistics . I am working in the function "nls" in the [R 2.3.1] with 246 data and want to fit a model to vectors( v and u ) but I have a problem to use it u 5.000000e-13 2.179057e+03 6.537171e+03 1.089529e+04 1.525340e+04 1.961151e+04 2.396963e+04 2.832774e+04 3.268586e+04 3.704397e+04 4.140209e+04 4.576020e+04 5.011831e+04 5.447643e+04 v 8.382562e-01 4.090868e+02 1.311053e+03 2.124143e+03 3.365494e+03 2.138903e+03 7.687774e+03 1.028396e+04 1.004186e+04 2.059798e+04 1.438464e+04 2.861373e+04 2.294919e+04 2.807701e+04 nls(v~c0+.5(a^2)*(u^2),start=list(c0=0,a=.3)) Error in eval(expr, envir, enclos) : attempt to apply non-function ............................................................................... nls(v~c0+a*(u^s),start=list(c0=0,a=10000,s=5000)) Error in numericDeriv(form[[3]], names(ind), env) : Missing value or an infinity produced when evaluating the model ................................................................................ i dont know how to solve it, please help me . best regards Sadeghian. __________________________________________________ [[alternative HTML version deleted]]
dear list I am student M.S. statistics in department statistics . I am working in the function "nls" in the [R 2.3.1] with 246 data and want to fit a model to vectors( v and u ) but I have a problem to use it u 5.000000e-13 2.179057e+03 6.537171e+03 1.089529e+04 1.525340e+04 1.961151e+04 2.396963e+04 2.832774e+04 3.268586e+04 3.704397e+04 4.140209e+04 4.576020e+04 5.011831e+04 5.447643e+04 v 8.382562e-01 4.090868e+02 1.311053e+03 2.124143e+03 3.365494e+03 2.138903e+03 7.687774e+03 1.028396e+04 1.004186e+04 2.059798e+04 1.438464e+04 2.861373e+04 2.294919e+04 2.807701e+04 nls(v~c0+.5(a^2)*(u^2),start=list(c0=0,a=.3)) Error in eval(expr, envir, enclos) : attempt to apply non-function ............................................................................... nls(v~c0+a*(u^s),start=list(c0=0,a=10000,s=5000)) Error in numericDeriv(form[[3]], names(ind), env) : Missing value or an infinity produced when evaluating the model ................................................................................ i dont know how to solve it, please help me . best regards Sadeghian. __________________________________________________ [[alternative HTML version deleted]]
azadeh sadeghian wrote:> > dear list > I am student M.S. statistics in department statistics . I am working in > the function "nls" in the [R 2.3.1] with 246 data and want to fit a model > to vectors( v and u ) but I have > a problem to use it > >Thanks for providing a reproducible example. Your version of R is _really_ old: you should probably update (or ask you administrator to update) to make sure that all possible bugs etc. are fixed. u=c(5.000000e-13,2.179057e+03,6.537171e+03,1.089529e+04,1.525340e+04, 1.91151e+04,2.396963e+04,2.832774e+04,3.268586e+04,3.704397e+04, 4.140209e+04,4.576020e+04,5.011831e+04,5.447643e+04) v=c(8.382562e-01,4.090868e+02,1.311053e+03,2.124143e+03,3.365494e+03, 2.138903e+03,7.687774e+03,1.028396e+04,1.004186e+04,2.059798e+04, 1.438464e+04,2.861373e+04,2.294919e+04,2.807701e+04) ## always a good idea to look at the data plot(v~u) ## your code: error nls(v~c0+.5(a^2)*(u^2),start=list(c0=0,a=.3)) ## you need a * between ".5" and "(a^2)" m2 = nls(v~c0+.5*(a^2)*(u^2),start=list(c0=0,a=.3)) coef(n2) ## you can also fit this (quadratic regression) with lm m3 = lm(v~I(u^2)) ## converting the coefficient sqrt(2*coef(m3)[2]) ## you need to use sensible starting conditions! ## one way to get is to look at the plot and ## take a guess. Another would be to assume ## c0=0 and fit a linear model to log(v) as a function ## of log(u) nls(v~c0+a*(u^s),start=list(c0=0,a=1,s=2)) -- View this message in context: http://www.nabble.com/please-help-me-tf4657131.html#a13309307 Sent from the R help mailing list archive at Nabble.com.
Hello. Error in optim(ini, .loss.vario, method = "L-BFGS-B", hessian = TRUE, : non-finite value supplied by optim I have this errore in fit the model"power" in simulation with the function g<-function(n=100,max=100,c0=0,ce=.005,ae=1.5,nsim=1000){ var.exp<-function(c0,ce,ae,h){ f<-c0+ce*(h^ae) return(f) } ms1<-ms2<-rep(NA,nsim) integrand1<-function(h) {(var.exp(c0,ce,ae,h)-var.exp(c0HAT1,ceHAT1,aeHAT1,h))^2} integrand2<-function(z) {(var.exp(c0,ce,ae,z)-var.exp(c0HAT2,ceHAT2,aeHAT2,z))^2} data<-grf(n=n,grid="reg",nsim=nsim,cov.model="power",xlim=c(0,max),ylim=c(0,max),cov.pars=c(ce,ae)) var1<-variog(data,option="bin") var2<-variog(data,option="cloud") for(i in (1:nsim)){ cat(i,"\n") ww1<-variofit(var1,ini.cov.pars=c(ce,ae),cov.model="power",simul.number=i,fix.nugget=F,weight="cressie") ww2<-variofit(var2,ini.cov.pars=c(ce,ae),cov.model="power",simul.number=i,fix.nugget=F,weight="equal") c0HAT1<-ww1$nugget ceHAT1<-ww1$cov.pars[1] aeHAT1<-ww1$cov.pars[2] c0HAT2<-ww2$nugget ceHAT2<-ww2$cov.pars[1] aeHAT2<-ww2$cov.pars[2] MISEmodel1<-integrate(integrand1,.1,max)$value MISEmodel2<-integrate(integrand2,.1,max)$value ms1[i]<-MISEmodel1 ms2[i]<-MISEmodel2 } plot(data) lines(ww1,type="l") lines(ww2,lty=2,lwd=2) return(MISEmodel1,MISEmodel2) } ............................................................................... when i simulation n=150 data with nsim=1000 i have thise problem in work with the function(g) Error: cannot allocate vector of size 80437 Kb In addition: Warning messages: 1: Reached total allocation of 255Mb how i can solve it? best regards. Sadeghian. __________________________________________________ [[alternative HTML version deleted]]
Hello. Error in optim(ini, .loss.vario, method = "L-BFGS-B", hessian = TRUE, : non-finite value supplied by optim I have this errore in fit the model"power" in simulation with the function g<-function(n=100,max=100,c0=0,ce=.005,ae=1.5,nsim=1000){ var.exp<-function(c0,ce,ae,h){ f<-c0+ce*(h^ae) return(f) } ms1<-ms2<-rep(NA,nsim) integrand1<-function(h) {(var.exp(c0,ce,ae,h)-var.exp(c0HAT1,ceHAT1,aeHAT1,h))^2} integrand2<-function(z) {(var.exp(c0,ce,ae,z)-var.exp(c0HAT2,ceHAT2,aeHAT2,z))^2} data<-grf(n=n,grid="reg",nsim=nsim,cov.model="power",xlim=c(0,max),ylim=c(0,max),cov.pars=c(ce,ae)) var1<-variog(data,option="bin") var2<-variog(data,option="cloud") for(i in (1:nsim)){ cat(i,"\n") ww1<-variofit(var1,ini.cov.pars=c(ce,ae),cov.model="power",simul.number=i,fix.nugget=F,weight="cressie") ww2<-variofit(var2,ini.cov.pars=c(ce,ae),cov.model="power",simul.number=i,fix.nugget=F,weight="equal") c0HAT1<-ww1$nugget ceHAT1<-ww1$cov.pars[1] aeHAT1<-ww1$cov.pars[2] c0HAT2<-ww2$nugget ceHAT2<-ww2$cov.pars[1] aeHAT2<-ww2$cov.pars[2] MISEmodel1<-integrate(integrand1,.1,max)$value MISEmodel2<-integrate(integrand2,.1,max)$value ms1[i]<-MISEmodel1 ms2[i]<-MISEmodel2 } plot(data) lines(ww1,type="l") lines(ww2,lty=2,lwd=2) return(MISEmodel1,MISEmodel2) } ............................................................................... when i simulation n=150 data with nsim=1000 i have thise problem in work with the function(g) Error: cannot allocate vector of size 80437 Kb In addition: Warning messages: 1: Reached total allocation of 255Mb how i can solve it? best regards. Sadeghian. __________________________________________________ [[alternative HTML version deleted]]
I have thise problem in work with the function variofit and nls and dont know how to solve it. var1<-variog(data,option="bin") var2<-variog(data,option="cloud") v1<-var1$v u1<-var1^u v2<-var2$v u2<-var2$u variofit(var1,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") variofit: weights used: equal variofit: minimisation function used: optim Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : missing value where TRUE/FALSE needed In addition: Warning message: unreasonable initial value for sigmasq + nugget (too low) in: variofit(var1, ini.cov.pars = c(0.005, 1.5), cov.model = "power", ....................................................................................................................... variofit(var2,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") variofit: weights used: equal warning: minimisation function nls can not be used with given cov.model. changing for "optim". variofit: minimisation function used: optim Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : missing value where TRUE/FALSE needed In addition: Warning message: In variofit(var2, ini.cov.pars = c(0.005, 1.5), cov.model = "power", : unreasonable initial value for sigmasq + nugget (too low) ............................................................................................................................... nls(v2~c0+ce*(1-exp(-(u2^2)/(ae^2))),start=list(c0=0,ae=30000,ce=20000)) Error in nls(v2 ~ c0 + ce * (1 - exp(-(u2^2)/(ae^2))), start = list(c0 = 0, : number of iterations exceeded maximum of 50 best regards. Sadeghian. __________________________________________________ [[alternative HTML version deleted]]
Dear list. I am student M.S. statistics in department statistics .I have thise problem in work with the function variofit and nls and dont know how to solve it. var1<-variog(data,option="bin") var2<-variog(data,option="cloud") v1<-var1$v u1<-var1^u v2<-var2$v u2<-var2$u variofit(var1,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") variofit: weights used: equal variofit: minimisation function used: optim Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : missing value where TRUE/FALSE needed In addition: Warning message: unreasonable initial value for sigmasq + nugget (too low) in: variofit(var1, ini.cov.pars = c(0.005, 1.5), cov.model = "power", ....................................................................................................................... variofit(var2,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") variofit: weights used: equal warning: minimisation function nls can not be used with given cov.model. changing for "optim". variofit: minimisation function used: optim Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : missing value where TRUE/FALSE needed In addition: Warning message: In variofit(var2, ini.cov.pars = c(0.005, 1.5), cov.model = "power", : unreasonable initial value for sigmasq + nugget (too low) ............................................................................................................................... nls(v2~c0+ce*(1-exp(-(u2^2)/(ae^2))),start=list(c0=0,ae=30000,ce=20000)) Error in nls(v2 ~ c0 + ce * (1 - exp(-(u2^2)/(ae^2))), start = list(c0 = 0, : number of iterations exceeded maximum of 50 best regards. Sadeghian. __________________________________________________ [[alternative HTML version deleted]]
Hi Azadeh, As the warning message is telling you, it seems that your initial parameters for the covariance functions are not very good. Something that you can do is to use the eyefit() function (package geoR) to fit your variogram "by eye" and get a first approximation for your covariance parameter values (or to test if the values you are using do generate a variogram curve that is close to your data). Then you can use these parameters values as initial values in the variofit() function. Julian azadeh sadeghian wrote:> I have thise problem in work with the function variofit and nls and dont know how to solve it. > var1<-variog(data,option="bin") > var2<-variog(data,option="cloud") > v1<-var1$v > u1<-var1^u > v2<-var2$v > u2<-var2$u > variofit(var1,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") > variofit: weights used: equal > variofit: minimisation function used: optim > Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : > missing value where TRUE/FALSE needed > In addition: Warning message: > unreasonable initial value for sigmasq + nugget (too low) in: variofit(var1, ini.cov.pars = c(0.005, 1.5), cov.model = "power", > ....................................................................................................................... > variofit(var2,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") > variofit: weights used: equal > warning: minimisation function nls can not be used with given cov.model. > changing for "optim". > variofit: minimisation function used: optim > Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : > missing value where TRUE/FALSE needed > In addition: Warning message: > In variofit(var2, ini.cov.pars = c(0.005, 1.5), cov.model = "power", : > unreasonable initial value for sigmasq + nugget (too low) > ............................................................................................................................... > nls(v2~c0+ce*(1-exp(-(u2^2)/(ae^2))),start=list(c0=0,ae=30000,ce=20000)) > Error in nls(v2 ~ c0 + ce * (1 - exp(-(u2^2)/(ae^2))), start = list(c0 = 0, : > number of iterations exceeded maximum of 50 > best regards. > Sadeghian. > > > __________________________________________________ > > > > [[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.
Well Sadeghian, I have to give you credit for perseverance. This must be the fifth email you have sent to R-help for this one question. Unfortunately, with each additional message, your chances of getting any help are becoming asymptotically closer to zero. So some advice: > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. I think you definitely need to read the posting guide, and then maybe you could try to come up with some code using a small portion of your data set that would illustrate your problem? As it stands, nobody can attempt to reproduce your error to see what the problem is, so how can anybody possibly help? Best, Jim azadeh sadeghian wrote:> Dear list. > I am student M.S. statistics in department statistics .I have thise problem in work with the function variofit and nls and dont know how to solve it. > var1<-variog(data,option="bin") > var2<-variog(data,option="cloud") > v1<-var1$v > u1<-var1^u > v2<-var2$v > u2<-var2$u > variofit(var1,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") > variofit: weights used: equal > variofit: minimisation function used: optim > Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : > missing value where TRUE/FALSE needed > In addition: Warning message: > unreasonable initial value for sigmasq + nugget (too low) in: variofit(var1, ini.cov.pars = c(0.005, 1.5), cov.model = "power", > ....................................................................................................................... > variofit(var2,ini.cov.pars=c(0.005,1.5),cov.model="power",fix.nugget=F,weight="equal") > variofit: weights used: equal > warning: minimisation function nls can not be used with given cov.model. > changing for "optim". > variofit: minimisation function used: optim > Error in if (loss > (.Machine$double.xmax^0.5) | loss == Inf | loss == : > missing value where TRUE/FALSE needed > In addition: Warning message: > In variofit(var2, ini.cov.pars = c(0.005, 1.5), cov.model = "power", : > unreasonable initial value for sigmasq + nugget (too low) > ............................................................................................................................... > nls(v2~c0+ce*(1-exp(-(u2^2)/(ae^2))),start=list(c0=0,ae=30000,ce=20000)) > Error in nls(v2 ~ c0 + ce * (1 - exp(-(u2^2)/(ae^2))), start = list(c0 = 0, : > number of iterations exceeded maximum of 50 > best regards. > Sadeghian. > > __________________________________________________ > > > > [[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.-- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623