Re: [R] How to find when a value is reached given a function?

2021-01-25 Thread Abby Spurdle
You could use a spline to interpolate the points. (And I'd consider increasing the number of points if possible, say to 200). Then use a root finder, such as uniroot(), to solve for f(i) - k Where, k (a constant), would be 1e6, based on your example. There are a number of variations on this

Re: [R] How to find when a value is reached given a function?

2021-01-25 Thread Luigi Marongiu
If I run this: ``` Y = c(1, 2, 4, 8, 16, 32, 64, 128) X = 0:7 plot(Y~X, log='y') model <- lm(log10(Y) ~ X) abline(model) predict(model, data.frame(Y=log10(100))) ``` I get a funny answer: ``` 1 2 3 4 5 6 7 8

Re: [R] How to find when a value is reached given a function?

2021-01-25 Thread Luigi Marongiu
Thanks, I'll check it out. I ran the simulation and I got: ``` t = 1, N = 20,000 t = 2, N = 40,000 t = 3, N = 80,000 t = 4, N = 160,000 t = 5, N = 320,000 t = 6, N = 640,000 t = 7, N = 1,280,000 ``` Hence the answer is t=6.{...} but the problem is to get that fractional value. Would be possible

Re: [R] How to find when a value is reached given a function?

2021-01-24 Thread Duncan Murdoch
On 24/01/2021 2:57 p.m., Luigi Marongiu wrote: Hello I am trying to simulate a PCR by running a logistic equation. So I set the function: ``` PCR <- function(initCopy, dupRate, Carry) { ROI_T = initCopy A = array() for (i in 1:45) { ROI_TplusOne <- ROI_T * dupRate * (1 -

[R] How to find when a value is reached given a function?

2021-01-24 Thread Luigi Marongiu
Hello I am trying to simulate a PCR by running a logistic equation. So I set the function: ``` PCR <- function(initCopy, dupRate, Carry) { ROI_T = initCopy A = array() for (i in 1:45) { ROI_TplusOne <- ROI_T * dupRate * (1 - ROI_T/Carry) A[i] <- ROI_TplusOne ROI_T <- ROI_TplusOne