[R] modelling 4-parameter curve in R does not match data - how to proceed?

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Thu Mar 18 07:44:43 CET 2021


Oh, I got it! I was sending the fluorescence instead of the cycles x.
Thank you

```
desmos <- rutledge(list(half_fluorescence = 27.1102, slope = 2.76798,
                        max_fluorescence = 11839.8, back_fluorescence
= -138.864) , 1:45)
```

On Wed, Mar 17, 2021 at 8:58 PM Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>
> On 17/03/2021 12:37 p.m., Luigi Marongiu wrote:
> > sorry, I don't get it...
>
> Modify your rutledge function to print x, and you'll see the values of
> high printed.  x should be 1:45.
>
> Duncan Murdoch
>
> >
> > On Wed, Mar 17, 2021 at 2:35 PM Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
> >>
> >> On 17/03/2021 6:59 a.m., Luigi Marongiu wrote:
> >>> yes, but in `rutledge` I model y as `y = (M / ( 1 + exp(-(x-m)/s)) ) +
> >>> B`, with x being 1:45. Isn't that the equivalent of what I fed Desmos
> >>> with? Tx
> >>
> >> No, it's not.
> >>
> >> Duncan Murdoch
> >>
> >>>
> >>> On Wed, Mar 17, 2021 at 11:31 AM Duncan Murdoch
> >>> <murdoch.duncan using gmail.com> wrote:
> >>>>
> >>>> On 17/03/2021 5:41 a.m., Luigi Marongiu wrote:
> >>>>> Hello,
> >>>>> I have a dataset from a polymerase chain reaction. I am using the
> >>>>> equation given by Rutledge
> >>>>> (https://pubmed.ncbi.nlm.nih.gov/15601990/) but the profile I get in R
> >>>>> does not match the data. I ran the same thing in Desmos and instead
> >>>>> the profile is correct (attached).
> >>>>> Why do I not get the same matching model as in Desmos? I believe the
> >>>>> formula in R is the same as the one in Desmos, and I am using the same
> >>>>> parameters.
> >>>>> Is there a procedure to debug models?
> >>>>> Thanks
> >>>>>
> >>>>> Here is the code:
> >>>>> ```
> >>>>> high <- c(120.64, 66.14, 34.87, 27.11, 8.87, -5.8, 4.52, -7.16, -17.39,
> >>>>>           -14.29, -20.26, -14.99, -21.05, -20.64, -8.03, -21.56, -1.28, 15.01,
> >>>>>           75.26, 191.76, 455.09, 985.96, 1825.59, 2908.08, 3993.18, 5059.94,
> >>>>>           6071.93, 6986.32, 7796.01, 8502.25, 9111.46, 9638.01, 10077.19,
> >>>>>           10452.02, 10751.81, 11017.49, 11240.37, 11427.47, 11570.07, 11684.96,
> >>>>>           11781.77, 11863.35, 11927.44, 11980.81, 12021.88)
> >>>>> plot(1:45, high, type = "l")
> >>>>> rutledge <- function(p, x) {
> >>>>>      m = p$half_fluorescence
> >>>>>      s = p$slope
> >>>>>      M = p$max_fluorescence
> >>>>>      B = p$back_fluorescence
> >>>>>      y = (M / ( 1 + exp(-(x-m)/s)) ) + B
> >>>>>      return(y)
> >>>>> }
> >>>>> desmos <- rutledge(list(half_fluorescence = 27.1102, slope = 2.76798,
> >>>>>                            max_fluorescence = 11839.8, back_fluorescence
> >>>>> = -138.864) , high)
> >>>>>
> >>>>> points(1:45, desmos, type="l", col="blue")
> >>>>
> >>>>
> >>>> In your calculation of desmos, you are using the Y variable for x in the
> >>>> formula.  Calculate it this way instead:
> >>>>
> >>>> desmos <- rutledge(list(half_fluorescence = 27.1102, slope = 2.76798,
> >>>>                              max_fluorescence = 11839.8, back_fluorescence
> >>>>     = -138.864) , 1:45)
> >>>>
> >>>> Duncan Murdoch
> >>>>
> >>>
> >>>
> >>
> >
> >
>


-- 
Best regards,
Luigi



More information about the R-help mailing list