-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathschema.jl
More file actions
47 lines (40 loc) · 1.83 KB
/
Copy pathschema.jl
File metadata and controls
47 lines (40 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@testset "schemas" begin
using StatsModels: schema, apply_schema, FullRank
f = @formula(y ~ 1 + a + log(b) + c + b & c)
y = rand(9)
b = rand(9)
df = (y = y, a = 1:9, b = b, c = repeat(["d", "e", "f"], 3))
f = apply_schema(f, schema(f, df))
@test f == apply_schema(f, schema(f, df))
df2 = (y = y, a = 1:9, b = b, c = [df.c; df.c])
df3 = (y = y, a = 1:9, b = b, c = repeat(["a", "b", "c"], 3))
df4 = (y = [df.y; df.y], a = [1:9; 1:9], b = [b; b], c = [df.c; df.c])
df5 = (z = y, a = 1:9, b = b, c = repeat(["d", "e", "f"], 3))
df6 = (y = y, a = 2:10, b = b, c = repeat(["a", "b", "c"], 3))
df7 = (w = y, d = 1:9, x = b, z = repeat(["d", "e", "f"], 3))
df8 = (y = y, a = 1:9, c = repeat(["d", "e", "f"], 3))
sch = schema(df, Dict(:c => DummyCoding(base="e")))
sch2 = schema(df, Dict(:c => EffectsCoding(base="e")))
@test schema(df) == schema(df2)
@test apply_schema(f, schema(df)) == apply_schema(f, schema(df2))
@test schema(df) != schema(df3)
@test schema(df) != schema(df4)
@test schema(df) != schema(df5)
@test schema(df) != schema(df6)
@test schema(df) != schema(df7)
@test schema(df) != schema(df8)
@test schema(df8) != schema(df)
@test apply_schema(f, schema(df)) == apply_schema(f, schema(df5))
@test sch != sch2
@test isequal(schema(df), schema(df2))
@test isequal(apply_schema(f, schema(df)), apply_schema(f, schema(df2)))
@test !isequal(schema(df), schema(df3))
@test !isequal(schema(df), schema(df4))
@test !isequal(schema(df), schema(df5))
@test !isequal(schema(df), schema(df6))
@test !isequal(schema(df), schema(df7))
@test !isequal(schema(df), schema(df8))
@test !isequal(schema(df8), schema(df))
@test isequal(apply_schema(f, schema(df)), apply_schema(f, schema(df5)))
@test !isequal(sch, sch2)
end