朱莉娅的GLM可以做加权最小二乘法吗?

时间:2015-03-19 03:46:37

标签: julia glm

我想运行加权最小二乘回归。 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包的示例?

1 个答案:

答案 0 :(得分:3)

我认为@ 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
相关问题