Julia 1.0. GLM 1.0.0.
My Basic Example
julia> using GLM, StatsBase
julia> y=[1:10;] ; X= hcat( fill(1,10), y.^2, y.^3 ); lm1= GLM.lm(X, y);
Basic Questions
-
is the sigma (i.e.,
sqrt(deviance(lm)/dof_residual(lm)
) already programmed into julia? -
is the f-statistic of the model (i.e., whether the model beats a constant) already available somewhere ?
My motivation is to try to write a function that prints regression output in a different format that I prefer. At first, I thought I would write a show
function, but then I figured that the spirit of julia is for the user not to replace the basics, but to write different functionsâŚor maybe add a particular kind of keyword that dispatches to my function?
Less Important Question on ftest
- how does ftest work? The example from the docs does not work:
julia> using DataFrames, GLM, StatsBase
julia> dat = DataFrame(Treatment=[1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2.],
Result=[1.1, 1.2, 1, 2.2, 1.9, 2, .9, 1, 1, 2.2, 2, 2],
Other=[1, 1, 2, 1, 2, 1, 3, 1, 1, 2, 2, 1]);
julia> using StatsModels
julia> mod = lm(@formula(Result ~ 1 + Treatment), dat);
ERROR: cannot assign variable Base.mod from module Main
Stacktrace:
[1] top-level scope at none:0
julia> mod = lm(@formula(Result ~ 1 + Treatment), dat);
ERROR: cannot assign variable Base.mod from module Main
Stacktrace:
[1] top-level scope at none:0
so, I tried to make up my own simpler example and without DataFrame:
julia> using GLM, StatsBase
julia> y=[1:10;] ; X= hcat( fill(1,10), y.^2, y.^3 );
julia> y=[1:10;] ; XX= hcat( fill(1,10), y.^2, y.^3, y.^4 );
julia> lm1= GLM.lm(X, y); lm2= GLM.lm(XX, y);
julia> ftest(lm2, lm1)
Error showing value of type GLM.FTestResult{2}:
ERROR: MethodError: no method matching Array{String,2}(::Int64, ::Int64)
Closest candidates are:
Array{String,2}(::UndefInitializer, ::Int64, ::Int64) where T at boot.jl:396
Array{String,2}(::UndefInitializer, ::Int64...) where {T, N} at boot.jl:400
Array{String,2}(::UndefInitializer, ::Integer, ::Integer) where T at sysimg.jl:143
...
Stacktrace:
[1] show(::IOContext{REPL.Terminals.TTYTerminal}, ::GLM.FTestResult{2}) at /Users/ivo/.julia/packages/GLM/8TwVM/src/ftest.jl:110
Prediction?
in R, one gets a predicted value like this. How do I do it in this simple example?
julia> using DataFrames, GLM
julia> y=[1:10;] ; X= hcat( fill(1,10), y.^2, y.^3 ); lm1= GLM.lm(X, y);
julia> predict( lm1, [ 1.0, 2.0, 3.0 ])
ERROR: MethodError: no method matching predict(::LinearModel{LmResp{Array{Float64,1}},DensePredChol{Float64,LinearAlgebra.Cholesky{Float64,Array{Float64,2}}}}, ::Array{Float64,1})