0

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

  • 1
    Can you please share the code and data within your question so to make it reproducible? Without looking at the code or the link to the picture of your data, I would say that a variable that has been used in constructing `logit` model is missing from `allmean`. Because we don't have access to your code or history of what you've been doing it's hard to say what is going on without a reproducible example. – Roman Luštrik Oct 15 '18 at 07:32
  • dunno how to attach my data here. please teach. Code: > library(readr) > tryews <- read_csv("tryews.csv", + col_types = cols(Date = col_date(format = "%d/%m/%Y"))) > View(tryews) > 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$pred.prob <- predict(logit, newdata=allmean, type="response") Error in eval(predvars, data, env) : object 'gdpp' not found – Eileen Ting Oct 15 '18 at 07:39
  • I tried to put the code in the original question. Sorry it is messy. not sure how to format it correctly – Eileen Ting Oct 15 '18 at 07:49
  • Please explore the formatting options when you edit your question. You will find many tips on how to prepare a reproducible example [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Roman Luštrik Oct 15 '18 at 08:32

0 Answers0