2

I am fitting a model in R by passing an SSasymp function to nls():

fit <- nls(y ~ SSasymp(log10(x), yf, y0, log_alpha), data = df)

I would like to find the intersection of this curve with the line y = 0.1. I.e., where these two functions meet:

Intersection of decay function with line y=0.1

However, when I run:

xVal <- predict(fit,list(y = 0.1))

Instead of a single x-value, I get a vector of 56 values, as well as values for yf, y0, and log_alpha:

> str(xVal)
 num [1:56] 0.609 0.585 0.538 0.509 0.494 ...
 - attr(*, "gradient")= num [1:56, 1:3] 0.108 0.14 0.204 0.244 0.265 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "yf" "y0" "log_alpha"

I can get the estimates for the model parameters:

> summary(fit)

Formula: y ~ SSasymp(log10(x), yf, y0, log_alpha)

Parameters:
          Estimate Std. Error t value Pr(>|t|)    
yf        -0.04421    0.01398  -3.164  0.00258 ** 
y0         0.68735    0.01175  58.519  < 2e-16 ***
log_alpha -1.80647    0.05352 -33.753  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

And can plug these in, after solving for x by hand:

x = ((Asym - R0)/(Asym - 0.1))^(exp(-lrc)*log(10))

But I'm wondering if there is a way to use predict(), or a similar function, to remove the need for all this algebra!

shbrainard
  • 377
  • 2
  • 9

1 Answers1

0

If you have the estimates, shouldn't something like this work?

x[which(SSasymp(log10(x), yf, y0, log_alpha) == 0.1)]

fekioh
  • 894
  • 2
  • 9
  • 22
  • What is x a vector of in this case? In my question, x is just the answer, after solving the equation for x, and plugging in 0.1. Before doing this, all I have is the nlsObject "fit". – shbrainard Oct 07 '20 at 15:37