# Weightened linear model in GLM.jl

**URL:** <https://discourse.julialang.org/t/weightened-linear-model-in-glm-jl/119962>\
**Category:** General Usage\
**Tags:** glm\
**Created:** [September 27, 2024, 1:22pm UTC](https://discourse.julialang.org/t/weightened-linear-model-in-glm-jl/119962 "2024-09-27T13:22:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![achjaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achjaj/32/22358_2.png) [@achjaj](https://discourse.julialang.org/u/achjaj)\
**Post date:** [September 27, 2024, 1:22pm UTC](https://discourse.julialang.org/t/weightened-linear-model-in-glm-jl/119962/1 "2024-09-27T13:22:24Z")

</div>

Hi,

I want to fit a plane to measured points, i.e., the function Z = aX + bY + c to data, where the Z coordinate (dependent variable) has a measurement error \sigma. The documentation for GLM.jl mentions that `lm` function can take a vector of weights, but I’m not sure what these weights are supposed to be. Can I simply use 1/\sigma^2 as the weights, similar to LsqFit.jl?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 27, 2024, 2:37pm UTC](https://discourse.julialang.org/t/weightened-linear-model-in-glm-jl/119962/2 "2024-09-27T14:37:53Z")

</div>

IIRC weights in GLM are frequency weights, see an old discussion here:

> [@Usage of different types of weights](https://discourse.julialang.org/t/usage-of-different-types-of-weights/4780):
>
> The [weights.jl file](https://github.com/JuliaStats/StatsBase.jl/blob/master/src/weights.jl) describes three types of weights: frequency weights, probability weights, and analytic weights. This is an amazing feature to Julia, as only commercial software like STATA and SAS understand the differences between these 3 weights. R and Python only understand one type of weight, which I think is something like an importance weight. Being able to use these 3 types of weights properly is crucial to the field that I work in (causal machine learning). Most software implementat…

---

<div class="post-metadata">

**Author:** ![achjaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/achjaj/32/22358_2.png) [@achjaj](https://discourse.julialang.org/u/achjaj)\
**Post date:** [September 27, 2024, 4:51pm UTC](https://discourse.julialang.org/t/weightened-linear-model-in-glm-jl/119962/3 "2024-09-27T16:51:44Z")

</div>

Thanks for your reply. Can you please elaborate more? Frequency of what?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 28, 2024, 6:21am UTC](https://discourse.julialang.org/t/weightened-linear-model-in-glm-jl/119962/4 "2024-09-28T06:21:28Z")

</div>

There’s a set of lecture notes on the linked thread that explains frequency, probability and analytical weights. In short, frequency here refers to the frequency of an observation.
