I am trying to learn to do multinomial logistic regression by following a guide by Princeton University (https://www.princeton.edu/~otorres/LogitR101.pdf). More specifically, I am putting in a few indicators and based on them, I want the model to predict the probability of the country experiencing currency crisis.
I can follow the guides until I got stuck at page 7 where I wrote {allmean$pred.prob <- predict(logit, newdata=allmean, type="response")}
That's when I got the error:
Error in eval(predvars, data, env) : object 'gdpp' not found
If I simplify the code to {predict (logit, type = "response")}
, then the code runs but it gives me 254 data points instead of 1, as per the example on the pdf link.
I'm trying to regress a series of indicators (GDP, current account balance, etc) against a binary crisis indicator. All independent variables are doubles, dependent variable is integer. The reason I renamed GDP
to gdpp
is to check if simple fix might work. It didn't. Appreciate if someone can help me understand what's going on. I hope I've given enough info for you to work on.
This is my view when I import database. Dataset
Sorry I dont know how to list the code more beautifully.
> library(readr)
tryews <- read_csv("tryews.csv", + col_types = cols(Date = col_date(format = "%d/%m/%Y")))
> logit<- glm(crisis ~ gdpp+STdebt+CAD+creditDom+REER, family=binomial(link=logit),data=tryews)
> allmean<- data.frame(x1=mean(tryews$gdpp),x2=mean(tryews$STdebt),x3=mean(tryews$CAD),x4=mean(tryews$creditDom),x5=mean(tryews$REER))
> allmean
x1 x2 x3 x4 x5 1 4.034252 168.4653 -3.608307 10.54016 82.96524
> allmean$pred.prob <- predict(logit, newdata=allmean, type="response")
Error in eval(predvars, data, env) : object 'gdpp' not found