[R] Error messages using nonlinear regression function (nls)
PIKAL Petr
petr.pikal at precheza.cz
Thu Oct 19 08:21:11 CEST 2017
Hi
Thanks for the code but where is Prop?
It is not a variable in germination data set so we do not know how you did the computation.
My wild guess is, that your Prop do not follow logistic curve and therefore no results from nlsList
Cheers
Petr
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Wall, Wade A
> ERDC-RDE-CERL-IL CIV
> Sent: Wednesday, October 18, 2017 5:58 PM
> To: r-help at r-project.org
> Subject: [R] Error messages using nonlinear regression function (nls)
>
> Hi all,
>
> I am trying to use nonlinear regression (nls) to analyze some seed germination
> data, but am having problems with error codes.
>
> The data that I have closely matches the germination dataset included in the
> drc package.
>
> Here is the head of the data
>
> temp species start end germinated TotSeeds TotGerminated Prop
> 1 10 wheat 0 1 0 20 0 0.0
> 2 10 wheat 1 2 0 20 0 0.0
> 3 10 wheat 2 3 0 20 0 0.0
> 4 10 wheat 3 4 0 20 0 0.0
> 5 10 wheat 4 5 0 20 0 0.0
> 6 10 wheat 5 6 4 20 4 0.2
>
> temp is the temperature under which the seeds were germinated, species
> denotes the species (wheat, mungbean, or rice)
> Start and end denote the beginning and end of a period of time and
> germinated denotes how many seeds germinated during
> that period of time. Prop represents the proportion of seeds that have
> germinated.
>
> I have attempted to mimic Fox and Weisberg's appendix to Nonlinear
> Regression found here.
> https://socserv.socsci.mcmaster.ca/jfox/Books/Companion/appendix/Appendix
> -Nonlinear-Regression.pdf
>
> My first step is to look at a single species, wheat, and use nls on the individual
> temperatures.
>
> I have tried to use both the nlsList function and to attempt to estimate the
> parameters using lm(), but I
> receive error messages on both. Here is the code.
>
> library(drc) ### for germination dataset
> data(germination)
>
> wheat = germination[germination$species == "wheat",] ### subset by wheat
> scatterplot(Prop ~ end|temp,data=wheat,box=FALSE,reg=FALSE) ### view the
> data
> wheat$temp = as.factor(wheat$temp) ### convert to factor
>
> ### First, try to use nlsList
> wheat.list <- nlsList(Prop ~ SSlogis(end,phi1,phi2,phi3)|
> temp,pool=FALSE,data=wheat) ###
>
> ### next, try to use lm to estimate starting parameters.
> wheat.list = list()
>
> for (i in 1:length(levels(wheat$temp))){
> tmpDat = wheat[wheat$temp == levels(wheat$temp)[i],]
> tmp.lm <- lm(Prop ~ end,data = tmpDat)
> tmp.nls <- nls(Prop ~ theta1 / (1 + exp(-(theta2 + theta3*end))),
> start = list(theta1 = .5,theta2=coef(tmp.lm)[1],theta3 = coef(tmp.lm)[2]),
> data = tmpDat,trace=TRUE)
> tmp2.nls <- nls(Prop ~ SSlogis(end,phi1,phi2,phi3),data=tmpDat)
> wheat.list[i] <- tmp.nls
> }
> #### End code
> nlsList just returns an empty list.
>
> When I try to loop through the individual temperatures, for the first
> temperature, nls converges when I provide
> starting values, but when I try to use SSlogis(), I get the error messsage
>
> Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
> NA/NaN/Inf in 'x'
>
> For the second temperature (16), I get the following error message when
> provided initial values using lm:
>
> Error in nls(Prop ~ theta1/(1 + exp(-(theta2 + theta3 * end))), start = list(theta1
> = 0.5, :
> singular gradient
>
> I have tried to read through posts, but none of them seem to apply to this case.
> The data seem relatively simply and
> I am not sure what I am doing wrong. Any help would be appreciated.
>
> Wade
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.
V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.
This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.
In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
More information about the R-help
mailing list