Pedro Carmona Ibáñez
2013-Oct-09 08:46 UTC
[R] How can I use the predict function in R in a logistic regression fitted years ago?
I have a problem that I am trying to resolve with no success. More than two days searching and I didn't get a single clue. Sorry if the answer is out there and I didn't find it. Suppose that you have a logistic equation regression (binary model) from an old model that you estimated some years ago. Therefore you know the parameters âk (k = 1, 2, ..., p) because they were estimated in the past. But you don't have the data that were used to fit the model. My question is: can I introduce this old estimated logistic model in R as an object (corresponding to a logistic regression model)? I would like to use the "predict" function to prove this logistic regression with a new set of data (present data) and then check the validity of this old model standing the test of time. And to use this function you need the object of the logistic regression model. Thank you very much in advance. [[alternative HTML version deleted]]
S Ellison
2013-Oct-09 12:22 UTC
[R] How can I use the predict function in R in a logistic regression fitted years ago?
> Suppose that you have a logistic equation regression (binary model) from an > old model that you estimated some years ago. Therefore you know the > parameters ?k (k = 1, 2, ..., p) because they were estimated in the > past. > But you don't have the data that were used to fit the model. > > My question is: can I introduce this old estimated logistic model in R as > an object (corresponding to a logistic regression model)?You have not said how you fitted the model, so you could have anything from an lm() object to glm, passing through various max likelihood and optimisation routines on the way, so the answer is properly 'maybe'. Having said that, for most practical purposes I think the answer is in practice 'no'. All the predict methods would require you to construct an object with the right class, containing as a minimum the parts of the object used by the relevant predict() method. For example, if you look at the code in predict.glm, one of the more common logistic modelling tools, that passes the fitted object to predict.lm and then uses an inverse link function to bring the predictions back into the binomial family space. So you will at least need to create enough of an object to keep predict.lm happy. That in turn will need things like the terms object, the contrasts, the call offset and so on. It also uses the object's residuals (for their length, if nothing else) and of course if you want standard errors on fit or prediction you'll need other things. Without the data that will all be very problematic and very tedious to invent. It would be far quicker to write a simple function that does the prediction for you from the parameters. S Ellison ******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}
Greg Snow
2013-Oct-09 15:08 UTC
[R] How can I use the predict function in R in a logistic regression fitted years ago?
You can create a glm fit with only an offset created from the coefficients that you have, then use the regular predict function with that. For example using the iris data (first fitting a model on the real data, then fitting a new model using dummy data and the coefficients from the first fit): fit1 <- glm( I(Species=='versicolor') ~ Petal.Length + Petal.Width, data=iris, family=binomial ) coef(fit1) dummydata <- data.frame( Petal.Length = rnorm(10), Petal.Width=rnorm(10), Species = rep(c('versicolor','other'), each=5) ) fit2 <- glm( I(Species=='versicolor') ~ 0 + offset(-2.863708 + 1.563076*Petal.Length - 3.153165*Petal.Width), data=dummydata, family=binomial ) pred1 <- predict(fit1, newdata=iris) pred2 <- predict(fit2, newdata=iris) plot(pred1,pred2) abline(0,1, col='green') On Wed, Oct 9, 2013 at 2:46 AM, Pedro Carmona Ibáñez <pedro.carmona@uv.es>wrote:> I have a problem that I am trying to resolve with no success. More than two > days searching and I didn't get a single clue. Sorry if the answer is out > there and I didn't find it. > > Suppose that you have a logistic equation regression (binary model) from an > old model that you estimated some years ago. Therefore you know the > parameters āk (k = 1, 2, ..., p) because they were estimated in the past. > But you don't have the data that were used to fit the model. > > My question is: can I introduce this old estimated logistic model in R as > an object (corresponding to a logistic regression model)? > > I would like to use the "predict" function to prove this logistic > regression with a new set of data (present data) and then check the > validity of this old model standing the test of time. And to use this > function you need the object of the logistic regression model. > > Thank you very much in advance. > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > 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. > >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]