0
votes

Problem context: model response variable 'status' for prediction. Help context: Error in UseMethod("predict"). My thinking is that the field 'status' factor is the issue. Need help in detecting issue in predict.

R code:

model.predict <- predict(model.fit, newdata = loans_train_data, type="response")

structure data:

str(loans_train_data)
'data.frame: 
$amount:num...
$...
$status: factor w/2 levels "Good", "Bad": 2, 1, 2, 1, 1, 1, 1 ...

Error in UseMethod("predict")

Error in UseMethod("predict") : 
no applicable method for 'predict' applied to an object of class "c('double', 'numeric')"

Things that work:

model.lm <- glm2(formula, data=loans_train_data, family="binomial")
model.fit <- fitted(model.lm)

Fails on predict, with Error in UseMethod("predict").

model.predict <- predict(model.fit, newdata=loans_train_data, type="response")
1
S3 method dispatch, which predict uses, happens on the first argument, not newdata. What is class(model.fit)?smingerson
class(model.fit) is [1] numericuser1857373
I re-arranged the first argument, e.g, c('status', 'rate', 'income'...). The first run example had c('loan_id', 'status', 'rate', 'income'...).user1857373

1 Answers

1
votes

Use predict on model.lm. Per the documentation for fitted, https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/fitted, it extracts a vector of values, not the model itself.