-
Notifications
You must be signed in to change notification settings - Fork 83
Additional show info for PCA
#90
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
Changes from 4 commits
923ca2f
5c9b6dd
6540e8f
78c24ae
d313dd4
2cb0251
e31458a
07331d6
03bdfd4
63baa5a
16c9b75
15f96d4
6807a4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -47,11 +47,27 @@ transform(M::PCA{T}, x::AbstractVecOrMat{T}) where {T<:Real} = transpose(M.proj) | |||||
| reconstruct(M::PCA{T}, y::AbstractVecOrMat{T}) where {T<:Real} = decentralize(M.proj * y, M.mean) | ||||||
|
|
||||||
| ## show & dump | ||||||
|
|
||||||
| function show(io::IO, M::PCA) | ||||||
| print(io, "PCA(indim = $(indim(M)), outdim = $(outdim(M)), principalratio = $(principalratio(M)))") | ||||||
| end | ||||||
|
|
||||||
| function show(io::IO, ::MIME"text/plain", M::PCA) | ||||||
| print(io, "PCA(indim = $(indim(M)), outdim = $(outdim(M)), principalratio = $(principalratio(M)))") | ||||||
| ldgs = projection(M) * diagm(0 => sqrt.(M.prinvars)) | ||||||
| rot = diag(ldgs' * ldgs) | ||||||
| ldgs = ldgs[:,sortperm(rot, rev=true)] | ||||||
|
Tokazama marked this conversation as resolved.
Outdated
|
||||||
| ldgs_signs = sign.(sum(ldgs, dims=1)) | ||||||
| ldgs_signs[ldgs_signs .== 0] .= 1 | ||||||
|
Tokazama marked this conversation as resolved.
Outdated
|
||||||
| ldgs = ldgs * diagm(0 => ldgs_signs[:]) | ||||||
| print(io, "\n\nPattern matrix\n") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(for consistency with below) Also, better be specific about what this matrix is: psych says "standardized loadings". |
||||||
| display(ldgs) | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if this came out with columns and rows labeled but without access to the variable names that's not possible. In the current state the columns are the components in the same order as those in the following coeftable.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's annoying. For now maybe print a Also, how about printing the second table first? That's the most important result I think.
Tokazama marked this conversation as resolved.
Outdated
|
||||||
| print(io, "\n") | ||||||
| print(io, "Importance of components:\n") | ||||||
| print(io, CoefTable(vcat(principalvars(M)', (principalvars(M) ./ tvar(M))', (cumsum(principalvars(M) ./tvar(M)))'), | ||||||
| string.("PC", 1:length(principalvars(M))), # components in order | ||||||
| ["Loadings", "Proportion explained", "Cumulative proportion"])) # row names | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Loadings" is "SS loadings" from psych, right? Shouldn't that be specified? Also "proportion" should say of what (the variance). And how about adding "proportion of variance" and "cumulative variance" which are in base R and psych?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are not "Loadings", they are "Eigenvalues" or "SS loadings" as R calls them. Loadings would be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @wildart You're definitely right. I apologize for the oversight. |
||||||
| end | ||||||
|
Tokazama marked this conversation as resolved.
|
||||||
|
|
||||||
| function dump(io::IO, M::PCA) | ||||||
| show(io, M) | ||||||
| println(io) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importis for when you overload a function with a new method. It shouldn't be needed here.