Search code examples
rsweave

R studio/Sweave object of type 'closure' is not subsettable


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)

Solution

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

    This, at least, should fix the accuracy problem.