[R] Error messages using nonlinear regression function (nls)

PIKAL Petr
Thu, 19 Oct 2017 06:21:11 -0000

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.