我想运行加权最小二乘回归。 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
关于julia - Julia 的 GLM 可以进行加权最小二乘吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29136889/