Skip to content
Browse files

Add show(LmMod); start change to GLM name

  • Loading branch information...
1 parent 7d6fb6c commit ce48f61e9dbd8c5d6192c178ee975e604909af31 @johnmyleswhite johnmyleswhite committed Jan 11, 2013
Showing with 62 additions and 14 deletions.
  1. +2 −2 LICENSE.md
  2. +6 −6 README.md
  3. +5 −3 src/Glm.jl
  4. +1 −1 src/RSC.jl
  5. +47 −0 src/show.jl
  6. +1 −2 test/glmFit.jl
View
4 LICENSE.md
@@ -1,8 +1,8 @@
-The Glm module is licensed under the MIT License:
+The GLM module is licensed under the MIT License:
> Copyright (c) 2012: Douglas Bates and other contributors.
>
-> https://github.com/JuliaStats/Glm.jl/contributors
+> https://github.com/JuliaStats/GLM.jl/contributors
>
> Permission is hereby granted, free of charge, to any person obtaining
> a copy of this software and associated documentation files (the
View
12 README.md
@@ -3,12 +3,12 @@
To install the package run (in Julia)
```julia
load("pkg")
-Pkg.add("Glm")
+Pkg.add("GLM")
```
-The `Glm` package depends on `DataFrames` and `Distributions`. Typically one loads it with
+The `GLM` package depends on `DataFrames` and `Distributions`. Typically one loads it with
```julia
-using DataFrames, Distributions, Glm
+using DataFrames, Distributions, GLM
```
to access the functions from all three packages. The `RDatasets`
package is useful for fitting models to compare with the results from
@@ -35,10 +35,10 @@ An example of a simple linear model in R is
(Intercept) 0.005085714 0.007833679 0.6492115 5.515953e-01
carb 0.876285714 0.013534536 64.7444207 3.409192e-07
```
-The corresponding model with the `Glm` package is
+The corresponding model with the `GLM` package is
```julia
-julia> using RDatasets, Glm
+julia> using RDatasets, GLM
julia> Formaldehyde = data("datasets", "Formaldehyde")
6x3 DataFrame:
@@ -73,7 +73,7 @@ with the corresponding Julia code
```julia
julia> LifeCycleSavings = data("datasets", "LifeCycleSavings")
...
-julia> fm2 = lm(sr ~ pop15+pop75+dpi+ddpi, LifeCycleSavings)
+julia> fm2 = lm(:(sr ~ pop15 + pop75 + dpi + ddpi), LifeCycleSavings)
...
julia> coeftable(fm2)
5x4 DataFrame:
View
8 src/Glm.jl
@@ -1,8 +1,8 @@
-module Glm
+module GLM
using DataFrames, Distributions
-import Base.\, Base.size
+import Base.\, Base.size, Base.show, Base.repl_show
import Distributions.deviance, Distributions.mueta, Distributions.var
export # types
@@ -427,5 +427,7 @@ function coeftable(mm::GlmMod)
DataFrame({cc, se, zz, 2.0 * ccdf(Normal(), abs(zz))},
["Estimate","Std.Error","z value", "Pr(>|z|)"])
end
-
+
+include("show.jl")
+
end # module
View
2 src/RSC.jl
@@ -106,7 +106,7 @@ end
tcrossprodPat{Tv,Ti}(A::SparseMatrixRSC{Tv,Ti}) = tcrossprodPat(A, Array(Ti, (0,)))
## DyeStuff example from the lme4 package for R
-#ZXt = SparseMatrixRSC(int32(hcat(Glm.gl(6,5), 7.*ones(Int, 30)))', ones(Float64,(2,30)))
+#ZXt = SparseMatrixRSC(int32(hcat(GLM.gl(6,5), 7.*ones(Int, 30)))', ones(Float64,(2,30)))
#ZXtZX = tcrossprodPat(ZXt,1:6)
#tcrossprod!(ZXt, copy(ZXtZX))
#Yield = float([1545, 1440, 1440, 1520, 1580, 1540, 1555, 1490, 1560, 1495, 1595, 1550, 1605, 1510, 1560, 1445, 1440, 1595, 1465, 1545, 1595, 1630, 1515, 1635, 1625, 1520, 1455, 1450, 1480, 1445])
View
47 src/show.jl
@@ -0,0 +1,47 @@
+function show(io::Any, obj::LmMod)
+ @printf("\n%s\n\nCoefficients:\n", obj.fr.formula)
+ @printf(" Term Estimate Std. Error t value Pr(>|t|)\n")
+ N = length(obj.pp.beta0)
+ for i = 1:N
+ @printf(" %12s%12.5f%12.5f%12.3f%12.3f %-3s\n",
+ obj.mm.model_colnames[i],
+ obj.pp.beta0[i],
+ obj.pp.beta0[i], # TODO: obj.std_errors[i],
+ obj.pp.beta0[i], # TODO: obj.t_statistics[i],
+ obj.pp.beta0[i], # TODO: obj.p_values[i],
+ p_value_stars(obj.pp.beta0[i])) # TODO: p_value_stars(obj.p_values[i]))
+ end
+ println("---\nSignif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1\n")
+ @printf("R-squared: %0.4f\n", 0.0) # TODO: obj.r_squared)
+end
+repl_show(io::Any, obj::LmMod) = show(io, obj)
+
+# function show(io::Any, obj::TestResult)
+# if length(obj.df) == 1
+# @printf("%8s Pr(>%s)\n%8.3f%8.3f",
+# @sprintf("%s(%d)", obj.distribution, obj.df[1]),
+# obj.distribution,
+# obj.test_statistic,
+# obj.p_value)
+# else
+# @printf("%8s Pr(>%s)\n%8.3f%8.3f",
+# @sprintf("%s(%d,%d)", obj.distribution, obj.df[1], obj.df[2]),
+# obj.distribution,
+# obj.test_statistic,
+# obj.p_value)
+# end
+# end
+
+function p_value_stars(p_value::Float64)
+ if p_value < 0.001
+ return "***"
+ elseif p_value < 0.01
+ return "**"
+ elseif p_value < 0.05
+ return "*"
+ elseif p_value < 0.1
+ return "."
+ else
+ return " "
+ end
+end
View
3 test/glmFit.jl
@@ -1,5 +1,4 @@
-load("Glm")
-using DataFrames, Distributions, Glm
+using DataFrames, Distributions, GLM
df = DataFrame(quote
counts = [18.,17,15,20,10,20,25,13,12]

0 comments on commit ce48f61

Please sign in to comment.
Something went wrong with that request. Please try again.