Skip to content
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

Cleanup Variables API #207

Open
wants to merge 26 commits into
base: devel
Choose a base branch
from
Open

Conversation

alyst
Copy link
Contributor

@alyst alyst commented Jun 17, 2024

Another round of cherry-picks from #193 that cleans up the variables API, as discussed in #199:

  • vars()/nvars() methods to get the vector of SEM model variables/count of variables.
  • observed_vars()/nobserved_vars() to get the vector of observed variables ordered as in observed data (nobserved_vars() replaces n_man() method)
  • latent_vars()/nlatent_vars() to get the vector of latent variables, preserving their order in vars()
  • get_data() renamed to samples(), nsamples() is the number of data points/samples/observations in the observed data (nsamples() replaces n_obs() method)
  • for SemMissingData nmeasured_vars() is the count of observed variables with measurements (within the given data pattern)
  • interface method definitions are moved from types.jl to the files, where the methods of a particular type are defined (new files are created to accommodate methods for the abstract classes, e.g. SemSpecification)
  • these variable API methods should work not only for the SEM specification objects, like RAMMatrices or ParameterTable, but also for the types that refer to SEM specification (SemImply, AbstractSem etc)
  • old methods using ambiguous terms get_colnames(), or get_n_nodes() removed

Per #199 discussion, an alternative to observed/latent terms would be manifest/latent. Also, samples could be replaced with observations (keeping both nobserved_vars() and nobservations() may lead to confusion), and measured/missing terms could be replaced with observed/missing. I really don't have a strong preference here, so if SEM stakeholders think manifest/latent + observed/missing is a better choice, I can update the PR.
Also, I think obs_cov/obs_mean have to be updated accordingly (observed_cov/observed_mean or manifest_cov/manifest_mean).

This PR should be really the last one that does not introduce improvements or new features, but it should help to make the improvements easier.

Comment on lines +163 to 164
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns
)
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns

@@ -143,9 +144,13 @@ function RAM(;
# μ
if meanstructure
has_meanstructure = Val(true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
has_meanstructure = Val(true)
!isnothing(M_indices) || throw(
ArgumentError(
"You set `meanstructure = true`, but your model specification contains no mean parameters.",
),
)

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 91.80328% with 15 lines in your changes missing coverage. Please review.

Project coverage is 70.65%. Comparing base (b2012b0) to head (cf50d8c).
Report is 1 commits behind head on devel.

Files Patch % Lines
src/frontend/specification/RAMMatrices.jl 71.42% 4 Missing ⚠️
src/observed/EM.jl 80.00% 4 Missing ⚠️
src/frontend/specification/StenoGraphs.jl 80.00% 2 Missing ⚠️
src/frontend/common.jl 80.00% 1 Missing ⚠️
src/frontend/fit/standard_errors/bootstrap.jl 0.00% 1 Missing ⚠️
src/frontend/fit/summary.jl 0.00% 1 Missing ⚠️
src/imply/RAM/generic.jl 93.33% 1 Missing ⚠️
src/imply/RAM/symbolic.jl 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #207      +/-   ##
==========================================
+ Coverage   69.64%   70.65%   +1.01%     
==========================================
  Files          51       52       +1     
  Lines        2421     2457      +36     
==========================================
+ Hits         1686     1736      +50     
+ Misses        735      721      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +163 to 164
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns
)
check_round(partable.columns[c][var_indices]; digits = digits) for c in var_columns

@@ -143,9 +144,13 @@ function RAM(;
# μ
if meanstructure
has_meanstructure = Val(true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
has_meanstructure = Val(true)
!isnothing(M_indices) || throw(
ArgumentError(
"You set `meanstructure = true`, but your model specification contains no mean parameters.",
),
)

@alyst
Copy link
Contributor Author

alyst commented Jun 27, 2024

@Maximilian-Stefan-Ernst I have also cleaned up the existing unit tests and added the tests to cover the vars/params API calls

"""
nparams(semobj)

Return the number of parameters in a SEM model associated with `semboj`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Return the number of parameters in a SEM model associated with `semboj`.
Return the number of parameters in a SEM model associated with `semobj`.


See also [`vars`](@ref).
"""
nvars(semobj) = length(vars(semobj))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function (and the next ones) do not seem to be exported - I think we should do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants