# Using Survey/Inverse Probability Weights in Regression

**URL:** https://discourse.julialang.org/t/using-survey-inverse-probability-weights-in-regression/10444
**Category:** Statistics
**Created:** [April 19, 2018, 5:57pm UTC](https://discourse.julialang.org/t/using-survey-inverse-probability-weights-in-regression/10444 "2018-04-19T17:57:22Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jhartma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jhartma/32/3989_2.png) [@jhartma](https://discourse.julialang.org/u/jhartma)
#### Post date: [April 19, 2018, 5:57pm UTC](https://discourse.julialang.org/t/using-survey-inverse-probability-weights-in-regression/10444/1 "2018-04-19T17:57:23Z")

</div>

Hi, I hope the answer is not too obvious as I am new to Julia.

I want to do some regressions with a weighted sample. At the moment I use the GLM package and I saw there are ProbabilityWeights, but I haven’t figured out how to use them together. Can anybody help?

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [April 19, 2018, 8:18pm UTC](https://discourse.julialang.org/t/using-survey-inverse-probability-weights-in-regression/10444/2 "2018-04-19T20:18:14Z")

</div>

GLM offers limited support for weights at the moment. The basic usage goes like,

```julia
using DataFrames, GLM
srand(0)
df = DataFrame(y = rand(1:10, 10),
               x = rand(10),
               w = rand(1:10, 10))
glm(@formula(y ~ x), df, Normal(), IdentityLink()) # OLS
glm(@formula(y ~ x), df, Normal(), IdentityLink(),
    wts = float.(df[:w])) # WLS

```

---

<div class="post-metadata">

### Author: ![jhartma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jhartma/32/3989_2.png) [@jhartma](https://discourse.julialang.org/u/jhartma)
#### Post date: [April 19, 2018, 8:43pm UTC](https://discourse.julialang.org/t/using-survey-inverse-probability-weights-in-regression/10444/3 "2018-04-19T20:43:34Z")

</div>

Thanks, it works smoothely.

Compared to R’s survey package I noticed smaller standard errors. Do you have any idea why?

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [April 19, 2018, 8:45pm UTC](https://discourse.julialang.org/t/using-survey-inverse-probability-weights-in-regression/10444/4 "2018-04-19T20:45:57Z")

</div>

GLM interprets weights as analytic (a.k.a. inverse variance) weights, like R’s `glm`. If you pass it sampling (a.k.a. inverse probability) weights, you’ll get incorrect standard errors.
