Luigi Marongiu
2025-Sep-20 14:38 UTC
[R] differing number of rows when running nls regression
@Krylov Thank you! now the preview works, but the actual nls still gives an error: ```> form = as.formula(Response ~ ( (exp((a+b*Dose))) / (1+exp(-(a+b*Dose)) ))) > preview(form, data = df, start=list(a=A, b=B))RSS: 33200000> nls(Response ~ ( (exp((a+b*Dose))) / (1+exp(-(a+b*Dose)) )),+ data=df, start=list(a=A, b=B)) Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : Missing value or an infinity produced when evaluating the model ``` @Berger Thank you and sorry for the typo: `x_25_2024` was the original data; it is `df` in the example. nls(form, data=df) worked for me too. On Sat, Sep 20, 2025 at 9:39?AM Ivan Krylov <ikrylov at disroot.org> wrote:> > ? Sat, 20 Sep 2025 08:02:16 +0200 > Luigi Marongiu <marongiu.luigi at gmail.com> ?????: > > > nls(Response ~ ( (exp(a+b*Dose)) / (1+exp-(a+b*Dose)) ), > > data=df, start=list(a=A, b=B)) > > Thank you for providing a reproducible example! > > 1+exp-(a+b*Dose) is parsed as 1 + `exp` - (a+b*Dose), treating `exp` as > a summand, and summing a function doesn't make sense in base R. > > In order to pass -(a+b*Dose) as the argument to exp(), this needs to be > written as 1+exp(-(a+b*Dose)) instead. > > -- > Best regards, > Ivan-- Best regards, Luigi