bgreenwell / investr

Inverse estimation in R
22 stars 6 forks source link

investr.nls working? #50

Closed ian-barr closed 10 months ago

ian-barr commented 10 months ago

The following gives an error using investr 1.4.2, stats 4.2.3, on R 4.2.3:

library(investr) 
x.df <- data.frame(a=c(0.5,.65,.8, 0.85, 0.95, .99), b = c(0.0,2,5, 10, 20,40)) 
cal <- nls(a ~ m*(1.0 - yin)*b/(b+y_0) + yin , data = x.df, start = list(m=1,y_0=5, yin=0.5)) 
calibrate(cal, y0 = c(0.75, 0.77, 0.73),  interval = "Wald", level = 0.95)

Error: 'cal' is not a valid matrix, list, or data frame.

Edit: This example from the documentation is working, but not the above for some reason.

mod<- nls(weight ~ theta1/(1 + exp(theta2 + theta3 * log(conc))),
+            start = list(theta1 = 1000, theta2 = -1, theta3 = 1),
+            data = nasturtium)
plotFit(mod, lwd.fit = 2)
invest(mod, y0 = c(309, 296, 419), interval = "inversion")

Edit 2: I didn't realize I was calling calibrate instead of invest. Works now.