Twang: Error: unexpected '=' in


#1

I'm new in Rstudio and am trying to familiarize myself with the package Twang to do propensity weighting. I'm using the code as described in the tutorial from the developers (RAND coorporation)

This is the first part of the code

library(twang)

set.seed(1)

data(lalonde)

ps.lalonde <- ps(treat ~ age + educ + black + hispan + nodegree +

  • married + re74 + re75,
  • data = lalonde,
  • n.trees=5000,
  • interaction.depth=2,
  • shrinkage=0.01,
  • perm.test.iters=0,
  • stop.method=c("es.mean","ks.max"),
  • estimand = "ATT",
  • verbose=FALSE)

I'm getting the following error message, though.

ps.lalonde <- ps(treat ~ age + educ + black + hispan + nodegree +

    • married + re74 + re75,
    • data = lalonde,
      Error: unexpected '=' in:
      "+ married + re74 + re75,
  • data ="
  • n.trees=5000,
    Error: unexpected ',' in "+ n.trees=5000,"
  • interaction.depth=2,
    Error: unexpected ',' in "+ interaction.depth=2,"
  • shrinkage=0.01,
    Error: unexpected ',' in "+ shrinkage=0.01,"
  • perm.test.iters=0,
    Error: unexpected ',' in "+ perm.test.iters=0,"
  • stop.method=c("es.mean","ks.max"),
    Error: unexpected ',' in "+ stop.method=c("es.mean","ks.max"),"
  • estimand = "ATT",
    Error: unexpected ',' in "+ estimand = "ATT","
  • verbose=FALSE)
    Error: unexpected ')' in "+ verbose=FALSE)"

Any suggestion what could be the cause and how to solve it?
Thanks,


#2

I believe you are just making a typo, have in mind that code shown in your tutorial is not in a "copy & paste" friendly format, you have to manually remove the "+" symbols of the left margin.

I runed this code and it worked normally:

library(twang)
set.seed(1)
data(lalonde)
ps.lalonde <- ps(treat ~ age + educ + black + hispan + nodegree + married + re74 + re75,
                 data = lalonde,
                 n.trees=5000,
                 interaction.depth=2,
                 shrinkage=0.01,
                 perm.test.iters=0,
                 stop.method=c("es.mean","ks.max"),
                 estimand = "ATT",
                 verbose=FALSE)

#3

This explains everything. It works now. It shows how novice I am in R.

Many thanks. You made my day.


#4

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:


#5

Have done it now. Thank you for raising this.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.