Using weights in rxLogit RRS feed

  • Question

  • Hi,

    I'm estimating a model using rxLogit from the RevoScaleR package. I want to include weights to account for the data being imbalanced, using the pweights option. 

    This works fine when I explicitly specify the formula inside the rxLogit command. However, when I specify the formula up front, the model ignores the pweights option and estimates the model as if there are no weights. See an example below:

    censusWorkers <- file.path(rxGetOption("sampleDataDir"), "CensusWorkers.xdf")
    dt <- rxImport(inData = censusWorkers)
    # Uses the weights
    rxLogit(sex~incwage, data=dt, pweights="perwt", reportProgress = 0)
    # Does not use the weights
    formula_rxLogit <- "sex ~ incwage"
    rxLogit(formula_rxLogit, data=dt, pweights="perwt", reportProgress = 0)

    Just writing the formula inside the rxLogit command is not really an option, as I need to select 100's of columns using regex functions. 

    Does anyone have an idea if I am doing something wrong, or how I could circumvent this problem without having to specify the formula explicitly?



    • Edited by Thomas1873 Wednesday, March 7, 2018 11:03 AM
    Wednesday, March 7, 2018 10:49 AM


  • Hi Thomas,

    This looks like a bug in rxLogit() - thanks for reporting the problem!

    A workaround you can use would be to use the rxGlm() function instead of rxLogit() to fit your binomial regression model:

    censusWorkers <- file.path(rxGetOption("sampleDataDir"), "CensusWorkers.xdf")

    formula_rxLogit <- "sex ~ incwage"

    # Gives correct results using weights.

    rxGlm(formula = formula_rxLogit, data=censusWorkers, pweights="perwt", reportProgress = 0,
          family = "binomial")

    • Proposed as answer by nielsbMVP Thursday, March 8, 2018 2:46 AM
    • Marked as answer by Thomas1873 Wednesday, March 14, 2018 10:07 AM
    Thursday, March 8, 2018 12:28 AM