Actually, I think it worked with chemCal, it was the drawing that was a bit rough. I sort it with: ``` library(MASS) lod <- dose.p(model,p=.95) plot(positivity ~ concentration, data = df, log = "x", xlab=expression(bold(paste("Concentration (c/", mu, "L)"))), ylab=expression(bold("Proportion of positivity"))) newdata <- data.frame(concentration=seq(min(df$concentration), max(df$concentration),by=0.01)) newdata$positivity = predict(model, newdata, type="response") abline(h=0.95, lty=3) abline(v=lod, lty=3) points(positivity ~ concentration, data = newdata, type="l") text(lod+0.2, 0.87, labels = round(lod, 2), cex = 0.9) ```
Case closed On Sat, Oct 2, 2021 at 4:33 PM Luigi Marongiu <marongiu.lu...@gmail.com> wrote: > > I tried with: > ``` > library(chemCal) > inverse.predict(model, 0.95) > > inverse.predict(model, 0.95) > $Prediction > [1] 0.4565871 > > $`Standard Error` > [1] 5.525725e-10 > > $Confidence > [1] 1.758532e-09 > > $`Confidence Limits` > [1] 0.4565871 0.4565871 > ``` > but the value 0.457 does not sound good, it should be about 1.7. Could > it be that model is based on glm whereas inverse.predict uses linear > regression? > > On Sat, Oct 2, 2021 at 10:14 AM Luigi Marongiu <marongiu.lu...@gmail.com> > wrote: > > > > Hello, > > I have set a glm model using probit. I would like to use it to predict > > X given Y. I have followed this example: > > ``` > > f2<-data.frame(age=c(10,20,30),weight=c(100,200,300)) > > f3<-data.frame(age=c(15,25)) > > f4<-data.frame(age=18) > > mod<-lm(weight~age,data=f2) > > > predict(mod,f3) > > 1 > > 150 > > > predict(mod,f4) > > 1 > > 180 > > ``` > > > > I have set the following: > > ``` > > df <- data.frame(concentration = c(1, 10, 100, 1000, 10000), > > positivity = c(0.86, 1, 1, 1, 1)) > > model <- glm(positivity~concentration,family = binomial(link = > > "logit"), data=df) > > > e3<-data.frame(concentration=c(11, 101), positivity=c(1, 1)) > > > predict(model, e3) > > 1 2 > > 5.645045 46.727573 > > ``` > > but: > > ``` > > > e4<-data.frame(positivity=0.95) > > > e4 > > positivity > > 1 0.95 > > > predict(model, e4) > > Error in eval(predvars, data, env) : object 'concentration' not found > > ``` > > Why did the thing worked for f4 but not e4? How do I get X given Y? > > Do I need to find the inverse function of logit (which one?) and apply > > this to the regression or is there a simpler method? > > Also, is it possible to plot the model to get a smooter line than > > `plot(positivity ~ concentration, data = df, log = "x", type="o")`? > > Thanks > > -- > > Best regards, > > Luigi > > > > -- > Best regards, > Luigi -- Best regards, Luigi
______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.