Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/MixedModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ using SparseArrays: nonzeros, nzrange, rowvals, sparse
using StaticArrays: StaticArrays, SVector
using Statistics: Statistics, mean, quantile, std
using StatsAPI: StatsAPI, aic, aicc, bic, coef, coefnames, coeftable, confint, deviance
using StatsAPI: dof, dof_residual, fit, fit!, fitted, isfitted, islinear, leverage
using StatsAPI:
loglikelihood, meanresponse, modelmatrix, nobs, pvalue, predict, r2, residuals
using StatsAPI: response, responsename, stderror, vcov, weights
using StatsAPI: dof, dof_residual, fit, fit!, fitted, isfitted, islinear, leverage, mss
using StatsAPI: loglikelihood, meanresponse, modelmatrix, nobs, pvalue, predict, r2
using StatsAPI: residuals, response, responsename, stderror, vcov, weights
using StatsBase: StatsBase, CoefTable, model_response, summarystats
using StatsFuns: log2π, normccdf
using StatsModels: StatsModels, AbstractContrasts, AbstractTerm, CategoricalTerm
using StatsModels: ConstantTerm, DummyCoding, EffectsCoding, FormulaTerm, FunctionTerm
using StatsModels: HelmertCoding, HypothesisCoding, InteractionTerm, InterceptTerm
using StatsModels: MatrixTerm, SeqDiffCoding, TableRegressionModel, Term
using StatsModels: apply_schema, drop_term, formula, lrtest, modelcols, term, @formula
using StatsModels: hasintercept
using StructTypes: StructTypes
using Tables: Tables, columntable
using TypedTables: TypedTables, DictTable, FlexTable, Table
Expand Down Expand Up @@ -107,6 +107,7 @@ export @formula,
fnames,
GHnorm,
glmm,
hasintercept,
isfitted,
islinear,
issingular,
Expand All @@ -118,6 +119,7 @@ export @formula,
lowerbd,
lrtest,
meanresponse,
mss,
modelmatrix,
model_response,
nobs,
Expand Down Expand Up @@ -214,7 +216,6 @@ include("profile/profile.jl")
include("nlopt.jl")
include("prima.jl")


# aliases with non-unicode function names
const settheta! = setθ!
const profilesigma = profileσ
Expand Down
9 changes: 9 additions & 0 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,15 @@ function StatsAPI.stderror(m::LinearMixedModel{T}) where {T}
return stderror!(similar(pivot(m), T), m)
end

function StatsAPI.mss(m::LinearMixedModel)
hasintercept(m) && return sum(abs2, meanresponse(m) .- fitted(m))
throw(
ArgumentError(
"Model sum of squares (MSS) is defined only for models with an intercept term."
),
)
end

"""
updateA!(m::LinearMixedModel)

Expand Down
2 changes: 2 additions & 0 deletions src/mixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function StatsAPI.dof_residual(m::MixedModel)
return nobs(m) - dof(m)
end

StatsModels.hasintercept(m::MixedModel) = hasintercept(formula(m))

"""
issingular(m::MixedModel, θ=m.θ; atol::Real=0, rtol::Real=atol>0 ? 0 : √eps)

Expand Down
4 changes: 4 additions & 0 deletions test/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ using Test
@test deviance(m1) ≈ deviance(m2)
@test isa(lmm(@formula(yield ~ 1 + (1|batch)), MixedModels.dataset(:dyestuff); progress=false, REML = true), LinearMixedModel)

@test mss(m1) ≈ 30780.69 rtol=0.005
m0 = fit(MixedModel, @formula(yield ~ 0 + (1|batch)), MixedModels.dataset(:dyestuff); progress=false)
@test_throws ArgumentError("Mean sum of squares is defined only for models with an intercept term.") mss(m0)

# example from https://github.com/JuliaStats/MixedModels.jl/issues/194
# copied from tetst/pls.jl
data = (
Expand Down
Loading