-
Notifications
You must be signed in to change notification settings - Fork 49
added StatsAPI.mss(m::LinearMixedModel) #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #816 +/- ##
=======================================
Coverage 97.33% 97.34%
=======================================
Files 36 36
Lines 3495 3499 +4
=======================================
+ Hits 3402 3406 +4
Misses 93 93
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Why is the test under Is this formula correct if the fixed-effects doesn't include a constant? Usually when Would it be better to write the loop as julia> @be m1 sum(abs2.(mean(_.y) .- fitted(_)))
Benchmark: 1804 samples with 4 evaluations
min 6.531 μs (69 allocs: 5.516 KiB)
median 7.146 μs (69 allocs: 5.516 KiB)
mean 13.561 μs (69 allocs: 5.516 KiB, 0.11% gc time)
max 8.763 ms (69 allocs: 5.516 KiB, 99.60% gc time)
julia> @be m1 sum(abs2, mean(_.y) .- fitted(_))
Benchmark: 2960 samples with 4 evaluations
min 6.729 μs (68 allocs: 5.484 KiB)
median 7.052 μs (68 allocs: 5.484 KiB)
mean 8.180 μs (68 allocs: 5.484 KiB, 0.13% gc time)
max 856.917 μs (68 allocs: 5.484 KiB, 96.40% gc time) |
I put it under test broken because the same value in R only matches up to two digits, and I wanted to get comments . Sorry this should have been a draft PR |
@dmbates Is model sum of squares even defined if there is no intercept in the model? |
I used the definition here (though it uses "explained" instead of "model"): https://en.wikipedia.org/wiki/Explained_sum_of_squares |
Is there an easy way to detect if an intercept has been included in the formula? I am thinking of adding code to throw an error if mss is called on a mixed model without intercept. |
Broadcast fusion reduces the number of arrays allocated, but fundamentally the limit is that |
I pushed a commit with an example for you. 😄 |
Thanks! PS: How did you push to my branch? |
That is what i thought, thanks for confirming! |
Based on this: https://timnewbold.github.io/teaching_resources/GLMs.html , |
Yes. I should have responded earlier but I have been occupied with family matters for the last couple of days. This is another example of a computation shortcut that, strictly speaking, applies only to linear models and only has relevance if you are doing the computation by hand. Unfortunately, people focus on the formula and not on why the result should be of use. If you have a linear model in which the constant is within the column span of the model matrix, X, and the sum of squared residuals is the measure of goodness of fit then you may want to compare the model that you fit to a trivial model consisting only of a constant. This formula is from a Pythagorean relationship of the residual from the full model and the residual for the constant model so that it provides the difference in the two sums of squared residuals. Hence this is the sum of squared residuals accounted for but the model For a GLM or a LMM the criterion for estimation of the coefficients isn't minimizing the sum of squared residuals so the rationale for looking at this quantity doesn't exist. If you want to compare the model that you fit versus a trivial model just use a likelihood ratio test. So much of what is taught about analysis of variance is based on computational shortcuts that are irrelevant when you are using computers to fit the model. Fisher understood the geometry of the tests but needed to make them available to people who didn't have his insight into n-dimensional geometry so he summarized the results in tables. If you had to fit every model by hand calculation you quickly came to employ computational shortcuts, but that is no longer important. Unfortunately formulas like this survive and people think they must be meaningful in their own right. |
I see that this PR adds a |
@dmbates In that case we can just discard this. I was just adding this to implement all relevant functions in |
Thanks. I think we are better off not including such methods and will close the PR. I do appreciate your work on this. |
related to #514
Did behavior change? Did you add need features? If so, please update NEWS.md
docs/NEWS-update.jl
to update the cross-references.Should we release your changes right away? If so, bump the version: