Skip to content

Commit

Permalink
Add missing cell example for rank deficient
Browse files Browse the repository at this point in the history
  • Loading branch information
dmbates committed Dec 18, 2017
1 parent fcdc3dd commit 7fff514
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ form = DataFrame(Any[[0.1,0.3,0.5,0.6,0.7,0.9],[0.086,0.269,0.446,0.538,0.626,0.
@test isapprox(coef(lm1), coef(lm2) .* [1., 10.])
end

@testset "rankdeficient" begin
# an example of rank deficiency caused by a missing cell in a table
dfrm = DataFrame([categorical(repeat(string.('A':'D'), inner = 6)),
categorical(repeat(string.('a':'c'), inner = 2, outer = 4))],
[:G, :H])
X = ModelMatrix(ModelFrame(Formula(nothing, :(1+G*H)), dfrm)).m
y = X * (1:size(X, 2)) + 0.1 * randn(MersenneTwister(1234321), size(X, 1))
inds = deleteat!(collect(1:length(y)), 7:8)
m1 = fit(LinearModel, X, y)
@test isapprox(deviance(m1), 0.28856700971719657)
Xmissingcell = X[inds, :]
ymissingcell = y[inds]
@test_throws LinAlg.PosDefException m2 = fit(LinearModel, Xmissingcell, ymissingcell)
m2p = fit(LinearModel, Xmissingcell, ymissingcell, true)
@test isapprox(deviance(m2p), 0.2859221258731563)
end

dobson = DataFrame(Counts = [18.,17,15,20,10,20,25,13,12],
Outcome = categorical(repeat(string.('A':'C'), outer = 3)),
Treatment = categorical(repeat(string.('a':'c'), inner = 3)))
Expand Down

0 comments on commit 7fff514

Please sign in to comment.