Skip to content

Commit c4170c6

Browse files
committed
aov1
1 parent a22b616 commit c4170c6

3 files changed

Lines changed: 20 additions & 21 deletions

File tree

docs/src/news.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Warning: Major changes in functions having arguments 'nlv' (laent variables) and
1212
Symbol type). Choice between several types of scaling is now allowed.
1313
- MLR functions: Functions other than **mlr** were removed.
1414
- Function **mbpca** renamed to **cpca**.
15+
- Function **aov1**: syntax changed.
1516
- Fuction **rclustplsr** temporary removed.
1617
- Package UMAP updated to 0.3
1718

src/_util.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ function dupl(X; digits::Int = 3)
146146
n = nro(X)
147147
rownum1 = []
148148
rownum2 = []
149-
@inbounds for i = 1:n
149+
@inbounds for i in axes(X, 1)
150150
@inbounds for j = (i + 1):n
151-
res = isequal(vrow(X, i), vrow(X, j))
151+
res = isequal(round.(vrow(X, i); digits), round.(vrow(X, j); digits))
152152
if res
153153
push!(rownum1, i)
154154
push!(rownum2, j)

src/aov1.jl

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
2-
aov1(x::Vector{String}, Y)
2+
aov1(X::AbstractArray{Q}, y::Vector{String}) where Q <: AbstractFloat
33
One-factor ANOVA test.
4-
* `x` : A categorical variable (class membership) (n). Must be a `Vector{String}`.
5-
* `Y` : Y-data (n, q).
4+
* `X` : X-data (n, p) whose columns are tested (independently).
5+
* `y` : A categorical variable (class membership) (n). Must be a `Vector{String}`.
66
77
## Examples
88
```julia
@@ -12,34 +12,32 @@ db = joinpath(path_jdat, "data/iris.jld2")
1212
@load db dat
1313
@names dat
1414
@head dat.X
15-
x = dat.X[:, 5]
16-
Y = dat.X[:, 1:4]
17-
tab(x)
15+
X = Matrix(dat.X[:, 1:4])
16+
y = dat.X[:, 5]
17+
tab(y)
1818
19-
res = aov1(x, Y) ;
19+
res = aov1(X, y) ;
2020
@names res
2121
res.SSF
2222
res.SSR
2323
res.F
2424
res.pval
2525
```
2626
"""
27-
function aov1(x::Vector{String}, Y)
28-
Y = ensure_mat(Y)
29-
Q = eltype(Y)
30-
n = length(x)
31-
tabx = tab(x)
27+
function aov1(X::AbstractArray{Q}, y::Vector{String}) where Q <: AbstractFloat
28+
X = ensure_mat(X)
29+
tabx = tab(y)
3230
lev = tabx.keys
3331
ni = tabx.vals
3432
nlev = length(lev)
35-
Xdummy = dummy(Q, x).Y
36-
Yc = fcenter(Y, colmean(Y))
37-
fitm = mlr(Xdummy, Yc)
38-
pred = predict(fitm, Xdummy).pred
39-
SSF = sum((pred.^2); dims = 1) # return matrix
40-
SSR = ssr(pred, Yc) # return matrix
33+
Ydummy = dummy(Q, y).Y
34+
Xc = fcenter(X, colmean(X))
35+
fitm = mlr(Ydummy, Xc)
36+
pred = predict(fitm, Ydummy).pred
37+
SSF = sum((pred.^2); dims = 1) # return a matrix
38+
SSR = ssr(pred, Xc) # return a matrix
4139
df_fact = nlev - 1
42-
df_res = n - nlev
40+
df_res = nro(X) - nlev
4341
MSF = SSF / df_fact
4442
MSR = SSR / df_res
4543
F = MSF ./ MSR

0 commit comments

Comments
 (0)