Julia 的 GLM 可以做加权最小二乘法吗?

Can Julia's GLM do weighted least squares?

我想要 运行 加权最小二乘回归。 GLM 包的文档似乎暗示这是一个选项,但我无法弄清楚语法应该是什么。

test = DataFrames.DataFrame(x = float([1:12]), y = randn(12), w)
lm(y~x, test)

假设我想通过一些加权向量对每个观察值进行加权

我试过了

fit(LinearModel, y~x, data, wts=[rep(.5,6), rep(.7,6)])

但是找不到匹配的方法。

是否有任何文档包含更多有关如何使用 GLM 包的示例?

我认为@rickhg12hs 说得对:

julia> using DataFrames

julia> using GLM

julia> test = DataFrames.DataFrame(x = float([1:12]), y = randn(12));

julia> glm(y ~ x,test, Normal(), IdentityLink(), wts=[rep(.5,6), rep(.2,6)])
DataFrames.DataFrameRegressionModel{GLM.GeneralizedLinearModel{GLM.GlmResp{Array{Float64,1},Distributions.Normal,GLM.IdentityLink},GLM.DensePredChol{Float64}},Float64}:

Coefficients:
              Estimate Std.Error z value Pr(>|z|)
(Intercept)   0.715555  0.506611 1.41243   0.1578
x            -0.137865 0.0827818 -1.6654   0.0958


julia> glm(y ~ x,test, Normal(), IdentityLink(), wts=[rep(.5,6), rep(.7,6)])
DataFrames.DataFrameRegressionModel{GLM.GeneralizedLinearModel{GLM.GlmResp{Array{Float64,1},Distributions.Normal,GLM.IdentityLink},GLM.DensePredChol{Float64}},Float64}:

Coefficients:
              Estimate Std.Error z value Pr(>|z|)
(Intercept)   0.914117   0.59612 1.53345   0.1252
x            -0.187296 0.0765347 -2.4472   0.0144