Hi,

is there a way to do weighted linear regression and predict the confidence interval in Julia? I think with glm it is only implemented for non weighted linear regression.

Thank you for your answers and have a nice day

Hi,

is there a way to do weighted linear regression and predict the confidence interval in Julia? I think with glm it is only implemented for non weighted linear regression.

Thank you for your answers and have a nice day

`glm`

supports `wts`

keyword argument

1 Like

Yeah but you get an error if you call predict with interval = :confidence if you use wts.

```
julia> df = DataFrame(x = [1, 2, 3.], y = [1, 3, 4.])
julia> df.w = [2, 3, 4]
julia> fit1 = glm(@formula(y ~ x), df, Normal(), wts = df.w)
julia> predict(fit1, df[:, [:x]], interval=:confidence)
3Ć3 DataFrame
ā Row ā prediction ā lower ā upper ā
ā ā Float64? ā Float64? ā Float64? ā
āāāāāāā¼āāāāāāāāāāāāā¼āāāāāāāāāāā¼āāāāāāāāāāā¤
ā 1 ā 1.24 ā 0.923618 ā 1.55638 ā
ā 2 ā 2.68 ā 2.50221 ā 2.85779 ā
ā 3 ā 4.12 ā 3.87927 ā 4.36073 ā
```

3 Likes

`lm`

actually gives

```
ERROR: prediction with confidence intervals not yet implemented for weighted regression
```

And I think you can raise the issue.

Ahh ok thank you. Is the only difference between glm and lm that you can specify the distribution of your data with glm and lm assumes normal distribution?

I am just learning generalized linear models course this semester. As far as I know, linear regression is equivalent to the glm with normal distribution and identity link function.