0

#adding packages and features

install.packages('MatchIt')
library(MatchIt)
ldata <- MatchIt::lalonde
ldata$hispan <- ifelse(ldata$race=='hispan',1,0)
ldata$white <- ifelse(ldata$race='white',1,0)

#model to find propensity scores

propscores <- fitted.values(glm(treat~age+educ+white+hispan+married+nodegree+re74+re75,
                                family=binomial, data=ldata))

#Returns error:

Error in `function (object, ...) \nobject`(list(treat = c(1L, 1L, 1L,  : 
  could not find function "function (object, ...) \nobject"

Code worked on my professor's code, but not on mine. I'm not sure why? I've tried library(glmnet) in case it's to do with the glm() function not being recognised.

Moosa ali
  • 13
  • 2
  • Same error was solved [here](https://stackoverflow.com/a/27725144/6912817) – Ric Nov 07 '22 at 19:36
  • I could not replicate. There was a syntax error in `ifelse(ldata$race='white',1,0)` which should be `ifelse(ldata$race=='white',1,0)` with double equals. Perhaps you have an object in your global environment that's causing an issue by shadowing something important. Taking a look at `conflicts(detail=TRUE)` much show something useful. Have you also tried restarting R and running everything again? – MrFlick Nov 07 '22 at 19:50

1 Answers1

0

Have had same problem, fixed after restarting R

Q.L
  • 1