0

I have done a logistic regression and no matter what my accuracy always comes out as 0. As I have been trying to fix this I am now getting the error "object of type 'closure' is not subsettable' My dataset is adultData Here is my code

options(scipen = 999)
glm.fit=glm (adultData$income~adultData$nativeCountry+adultData$sex+adultData$age, family=binomial)
summary(glm.fit)
glm.probs=predict(glm.fit,type="response")
glm.probs[1:10]
head(table(glm.probs, adultData$income))
dfU <- adultData
dfU$Pr = glm.probs
dfU$Label = ifelse(dfU$Pr>0.5, "YES", "NO")
head(dfU)
dfU$correct <- ifelse(dfU$income=="<=50k" && dfU$Label=="NO", 1,0)
dfU$correct <- ifelse(dfU$income==">50k" && dfU$Label=="YES", 1,  dfU$correct)
accuracy = (sum(df$correct)/nrow(dfU)*100)
cat("accuracy is ", accuracy)
  • This error means that you have named an object the same name as as a function and are not referring to your object properly. R thinks you are referring to the function of the same name and functions are not subsettable. Here `df` refers to the density function of the F distribution. – lmo Dec 12 '17 at 13:15

1 Answers1

0

The second to last line has a typo, df$correct should read dfU$correct.

This, at least, should fix the accuracy problem.

Frost_Maggot
  • 309
  • 2
  • 12