Julia examples
Each example constructs its own data. The documentation build executes these examples, and the test suite executes the README's Julia fitting examples.
Logistic regression
using SpectralMM, Distributions, GLM, Random
rng = MersenneTwister(71)
X = randn(rng, 100, 3)
y = Float64.(rand(rng, 100) .< 0.5)
model = SpectralMM.glm(X, y, Bernoulli(), LogitLink())
@assert length(coef(model)) == 4
@assert length(predict(model, X)) == 100
coef(model)4-element Vector{Float64}:
-0.02006501003624904
-0.37997911492894837
0.001758992754949947
0.18761977918256972Sparse inputs
The response is generated from the same design, so its length always matches the number of observations. Sparse storage is retained during fitting; optional covariance computation uses dense coefficient matrices.
using SpectralMM, Distributions, GLM, SparseArrays, Random
rng = MersenneTwister(72)
X = sprandn(rng, 200, 8, 0.3)
mu = 0.4 .+ X * fill(0.15, size(X, 2))
y = mu + randn(rng, size(X, 1))
model = SpectralMM.glm(X, y, Normal(), IdentityLink(); inference=false)
@assert length(y) == size(X, 1)
@assert length(coef(model)) == size(X, 2) + 1
@assert all(isfinite, predict(model, X))
coef(model)9-element Vector{Float64}:
0.4196078121909915
-0.03291313092308612
0.009195761516944463
0.08271954384842548
-0.13216709096518722
0.06399964227077326
0.21908939016452683
0.25259856966556554
0.5081425374547809Robust regression
using SpectralMM, Random
rng = MersenneTwister(73)
X = randn(rng, 100, 3)
y = 0.5 .+ X * [0.2, -0.3, 0.1] + randn(rng, 100)
model = SpectralMM.fit(X, y, PseudoHuber(); inference=false)
@assert length(coef(model)) == 4
coef(model)4-element Vector{Float64}:
0.5667256712582192
0.10941105340430869
-0.2750593482205364
0.12300997249428401