[R] differing number of rows when running nls regression

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Sat Sep 20 16:38:02 CEST 2025


@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 using disroot.org> wrote:
>
> В Sat, 20 Sep 2025 08:02:16 +0200
> Luigi Marongiu <marongiu.luigi using 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



More information about the R-help mailing list