0
votes
Test <- read.table("C:/Users/ARAB/Documents/user_table.csv", header=T)
testlog <- glm(Conv ~ active_days, family=binomial("logit"))

this is a code i am trying to run in R but am getting error

"Error in eval(expr, envir, enclos) : object 'Conv' not found"

This is my first day in R. Please help me. Also I can see Conv in data when i am using view() command. Conv is the outcome variable containing 1/0. Also in sas or spss we have the option of modelling 1 or 0 in a binary logit model. How can we use that in R or does this error have something to do with that.

3
In reply to your last sentence: perhaps glm(1-Conv ~ active_days, ...) will do? (i.e. just convert 'successes' to 'failures' on the fly by subtracting the response variable from 1)? - Ben Bolker

3 Answers

5
votes

As mentioned by @blindJesse you need to specify the data.frame where the variables are contained by using data=data.frame inside glm function or using one of the below alternatives

utils::data(anorexia, package="MASS") # using some R data

# Option 1 (the best one)
glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian, data = anorexia)

# Option 2: Using 'with'
with(anorexia, glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian))

# Option 3: Using 'attach' I don't like it
attach(anorexia)
glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian)

detach(anorexia) # detaching the data.

# Option 4: Using '$'
glm(anorexia$Postwt ~ anorexia$Prewt + Treat + offset(Prewt), family = gaussian)

A fifth option could be using [ which could be very similar to that in fourth option.

3
votes

You need to specify the data.frame, e.g.

testlog <- glm(Conv ~ active_days, data=Test, family=binomial("logit"))
0
votes

another reason for this error is if you don't leave space between the + sign , glm throws this error

  • Sasken