Using predict()
one can obtain the predicted value of the dependent variable (y
) for a certain value of the independent variable (x
) for a given model. Is there any function that predicts x
for a given y
?
For example:
kalythos <- data.frame(x = c(20,35,45,55,70),
n = rep(50,5), y = c(6,17,26,37,44))
kalythos$Ymat <- cbind(kalythos$y, kalythos$n - kalythos$y)
model <- glm(Ymat ~ x, family = binomial, data = kalythos)
If we want to know the predicted value of the model for x=50
:
predict(model, data.frame(x=50), type = "response")
I want to know which x
makes y=30
, for example.
The object of inverse prediction is to infer the value of a condition x* that caused an observed response y*, based on a linear model relating responses to conditions fit to training data.
Function predict() returns a named list of class Prediction() . Its most important element is $data which is a data. frame that contains columns with the true values of the target variable (in case of supervised learning problems) and the predictions.
The predict() function is used to predict the values based on the previous data behaviors and thus by fitting that data to the model. You can also use the confidence intervals to check the accuracy of our predictions. References.
Came across this old thread but thought I would add some other info. Package MASS has function dose.p for logit/probit models. SE is via delta method.
> dose.p(model,p=.6)
Dose SE
p = 0.6: 48.59833 1.944772
Fitting the inverse model (x~y) would not makes sense here because, as @VitoshKa says, we assume x is fixed and y (the 0/1 response) is random. Besides, if the data weren’t grouped you’d have only 2 values of the explanatory variable: 0 and 1. But even though we assume x is fixed it still makes sense to calculate a confidence interval for the dose x for a given p, contrary to what @VitoshKa says. Just as we can reparameterize the model in terms of ED50, we can do so for ED60 or any other quantile. Parameters are fixed, but we still calculate CI's for them.
Saw the previous answer is deleted. In your case, given n=50 and the model is binomial, you would calculate x given y using:
f <- function (y,m) {
(logit(y/50) - coef(m)[["(Intercept)"]]) / coef(m)[["x"]]
}
> f(30,model)
[1] 48.59833
But when doing so, you better consult a statistician to show you how to calculate the inverse prediction interval. And please, take VitoshKa's considerations into account.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With