Search code examples
r

ipwtm function in R: First argument a vector


I want to use ipwtm function in IPW package in r to estimate inverse probability weights,

Here are the data

dat=data.frame(newid=c("A","A","A","A","B","B","B"),b6smk=c(0,0,1,1,0,0,0),sex=c(0,0,0,0,1,1,1),age=c(50,51,52,53,60,61,62),e7=c(1,1,2,2,3,2,2),starttime=c(-1,0,1,2,-1,0,1),fuptime=c(0,1,2,3,0,1,2)
temp <- ipwtm(
  exposure = b6smk,
  family = "survival",
  numerator = ~ sex+age,
  denominator = ~ sex+age+e7,
  id = newid,
  tstart = starttime,
  timevar = fuptime,
  type = "first",
  data = dat)

and I get the following error message:

Error in split.default(tempdat$exposure, tempdat$id) : 
  first argument must be a vector

The type of "b6smk" is numeric, and I do not know why it is an error.

How can I solve this error?


Solution

  • I'm facing the same problem. I tried this and it helped.

    1. Turn all variable into numeric class. In haartdat in iptwm package, all variables are numeric class.

    https://www.rdocumentation.org/packages/ipw/versions/1.0-11/topics/ipwtm

    1. iptwm can't read the data.table. In your example, though dat is data.frame, keep reminding it.