SteffenMoritz / ridge

CRAN R Package: Ridge Regression with automatic selection of the penalty parameter
GNU General Public License v2.0
18 stars 11 forks source link

logisticRidge predict #16

Closed msundara1001 closed 2 years ago

msundara1001 commented 2 years ago

Hello, I am using logisticRidge function to ask how my binary variable (0/1) is related to a set of linear predictors. I am writing to ask for clarification on the ‘predict’ portion of the model.

After fitting a logisticRidge model, I am trying to use the predict function to get fitted probabilities of outcome. However, I appear to be getting different values when I use ‘predict’ and ‘predict’ but supplying the original data that I fitted the model to as new data:

data(mtcars) library(ridge) model<-logisticRidge(vs~.,data=mtcars) predict(model,type="response") predict(model,type="response",newdata=mtcars[,-8])

Which usage of predict provides accurate values?

I have tested this out on a several datasets and with different combinations of binary predictors and continuous predictors. They seem to produce the same mismatches in predict values. I am happy to provide more replicable examples if you would like me to.

Thank you for your time!

msundara1001 commented 2 years ago

Form writing my own function, I recognize that predict with new data being supplied is providing correct answers. I did want to ask as a follow up though: glmnet provides slightly different coefficients when compared to ridge for the same lambda values and dataset. That is to be expected though correct? Thank you for your time!

SteffenMoritz commented 2 years ago

Hello, Sundaram

thank your for opening an issue. Sorry for the late reply, I've been really busy last week.

This was indeed a bug for logistic ridge (linearRidge didn't have the issue). As you already found out, the results from predict(model,type="response",newdata=mtcars[,-8]) are the correct ones.

I guess, predict() without specifying newdata is used extremly seldom, thus nobody recognized until now. Really important to open an issue, you probably saved others from getting wrong results.

I uploaded an update to Github and submitted a fixed version to CRAN.

Use this to install the new version from Github:

library(devtools)
install_github("SteffenMoritz/imputeTS")

Should only be a few days, till the new version is also available via CRAN (install.packages)

SteffenMoritz commented 2 years ago

Closed - the error is fixed now :) Thanks a lot for opening the issue.