Skip to content

Commit

Permalink
Merge pull request #5 from fmg-jluchman/master
Browse files Browse the repository at this point in the history
Patch update to 3.4.1
  • Loading branch information
jluchman authored Jan 28, 2023
2 parents 5a1a651 + fed49f4 commit a9a20de
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 32 deletions.
30 changes: 20 additions & 10 deletions domin.ado
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! domin version 3.4.0 11/3/2022 Joseph N. Luchman
*! domin version 3.4.1 1/27/2023 Joseph N. Luchman

program define domin, eclass //history and version information at end of file

Expand Down Expand Up @@ -366,14 +366,19 @@ else {

mata: model_specs = domin_specs()

mata: model_specs.iv_string = st_local("ivs")
mata: model_specs.cdlcompu = st_local("conditional'")
mata: model_specs.cptcompu = st_local("complete")
mata: model_specs.mi = st_local("mi")
mata: model_specs.all_subsets_fitstat = st_numscalar(st_local("allfs"))
mata: model_specs.constant_model_fitstat = st_numscalar(st_local("consfs"))

mata: dominance(model_specs, &domin_call()) //invoke "dominance()" function in Mata
mata: model_specs.reg = st_local("reg")
mata: model_specs.dv = st_local("dv")
mata: model_specs.all = st_local("all")
mata: model_specs.weight = st_local("weight")
mata: model_specs.exp = st_local("exp")
mata: model_specs.touse = st_local("touse")
mata: model_specs.regopts = st_local("regopts")

mata: dominance(model_specs, &domin_call(), ///
st_local("conditional'"), st_local("complete"), ///
st_local("ivs"), ///
st_numscalar(st_local("allfs")), st_numscalar(st_local("consfs"))) //invoke "dominance()" function in Mata

/*translate r-class results into temp results*/
matrix `domwgts' = r(domwgts)
Expand Down Expand Up @@ -706,7 +711,7 @@ end
-greatly expanded, clarified, and updated the help file
-----
- domin version 3.1 - date - Apr 14, 2015
-updated epsilon - works with glm, mvdom, and regress; also migrated to Mata (though not recommended approach - weights nixed for esplilon)
-updated epsilon - works with glm, mvdom, and regress; also migrated to Mata (though not recommended approach - weights nixed for epslilon)
-reverse option to reverse "coding" of fitstat in ranks, standardized metric and complete dominance
-fixed tied ranks (used to randomly assign, - now share highest number)
-added "best dominance" - Com, Cond, Gen - in display (works with "reverse")
Expand All @@ -732,8 +737,13 @@ end
-clean up internal functions (naming and redundancy)
-update to terminology in documentation and reporting
---
domin version 3.4.0 - mth, day, 20xx
domin version 3.4.0 - November 3, 2022
- reorganization of Mata code; function to function passing; Mata struct to handle input specs
- lb_dominance.mlib now contains all complied Mata code for -domin- generalized for accommodating -domme- and future commands
- increased precision of passed 'all' and 'constant' fit stats
// 3.4.1 - January 27, 2023
- fixed Mata code (dominance.mata 0.0.1)
- increase flexibility to work with -domme-; 3.4.0 makes assumptions -domme- cannot meet
- does not force arguments but accepts single objects for command-specific needs
- records domin options directly (doesn't call them as local macros)
*/
2 changes: 1 addition & 1 deletion domin.sthlp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{smcl}
{* *! version 3.4.0 November 3, 2022 J. N. Luchman}{...}
{* *! version 3.4.1 January 27, 2023 J. N. Luchman}{...}
{cmd:help domin}

{title:Title}
Expand Down
59 changes: 38 additions & 21 deletions dominance.mata
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*! dominance.mata version 0.0.0 11/3/2022 Joseph N. Luchman
*! dominance.mata version 0.0.1 1/27/2023 Joseph N. Luchman

version 12.1

Expand All @@ -9,9 +9,7 @@ mata set matastrict on
struct domin_specs {
string scalar iv_string, cdlcompu, cptcompu, mi
real scalar all_subsets_fitstat, constant_model_fitstat
string scalar mi, reg, dv, all, weight, exp, touse, regopts
}
Expand All @@ -22,20 +20,29 @@ mata:
mata set matastrict on
void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
void dominance(struct domin_specs scalar model_specs, pointer scalar model_call, ///
string scalar cdlcompu, string scalar cptcompu, string scalar iv_string, ///
real scalar all_subsets_fitstat, real scalar constant_model_fitstat)
{
/*# object declarations*/
real matrix IV_antiindicator_matrix, conditional_dominance, weighted_order_fitstats, weighted_order1less_fitstats, weight_matrix, complete_dominance, select2IVfits, IV_indicator_matrix, sorted_two_IVs, compare_two_IVs
real matrix IV_antiindicator_matrix, conditional_dominance, ///
weighted_order_fitstats, weighted_order1less_fitstats, ///
weight_matrix, complete_dominance, select2IVfits, ///
IV_indicator_matrix, sorted_two_IVs, compare_two_IVs
string matrix IV_name_matrix
real rowvector fitstat_vector, orders, combin_at_order, combin_at_order_1less, general_dominance, standardized, focal_row_numbers, nonfocal_row_numbers, cpt_desig, indicator_weight, antiindicator_weight
real rowvector fitstat_vector, orders, combin_at_order, ///
combin_at_order_1less, general_dominance, standardized, ///
focal_row_numbers, nonfocal_row_numbers, cpt_desig, ///
indicator_weight, antiindicator_weight
real colvector binary_pattern, cdl3, cpt_setup_vec, select2IVs
string colvector IVs
real scalar number_of_IVs, number_of_regressions, display, fitstat, var1, var2, x, y
real scalar number_of_IVs, number_of_regressions, display, fitstat, ///
var1, var2, x, y
string scalar IVs_in_model
Expand All @@ -44,7 +51,7 @@ void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
/*parse the predictor inputs*/
t = tokeninit(wchars = (" "), pchars = (" "), qchars = ("<>")) //set up parsing rules
tokenset(t, model_specs.iv_string) //register the "iv_string" string scalar for parsing/tokenizing
tokenset(t, iv_string) //register the "iv_string" string scalar for parsing/tokenizing
IVs = tokengetall(t)' //obtain all IV sets and IVs as a vector
Expand Down Expand Up @@ -127,8 +134,9 @@ void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
}
IVs_in_model = invtokens(IV_name_matrix[., x]') //collect a distinct subset of IVs, then collpase names into single string separated by spaces
fitstat = (*model_call)(model_specs.mi, IVs_in_model, model_specs.all_subsets_fitstat, model_specs.constant_model_fitstat)
fitstat = (*model_call)(IVs_in_model, all_subsets_fitstat, ///
constant_model_fitstat, model_specs) //implement called model - will differ for domin vs. domme
fitstat_vector[1, x] = fitstat //add fitstat to vector of fitstats
Expand All @@ -154,7 +162,7 @@ void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
general_dominance = colsum((weight_matrix:*fitstat_vector)') //general dominance weights created by computing product of weights and fitstats and summing for each IV row-wise; in implementing the rows are transposed and column summed so it forms a row vector as will be needed to make it an "e(b)" vector
fitstat = rowsum(general_dominance) + model_specs.all_subsets_fitstat + model_specs.constant_model_fitstat //total fitstat is then sum of gen. dom. wgts replacing the constant-only model and the "all" subsets stat
fitstat = rowsum(general_dominance) + all_subsets_fitstat + constant_model_fitstat //total fitstat is then sum of gen. dom. wgts replacing the constant-only model and the "all" subsets stat
st_matrix("r(domwgts)", general_dominance) //return the general dom. wgts as r-class matrix
Expand All @@ -167,7 +175,7 @@ void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
st_numscalar("r(fs)", fitstat) //return overall fit statistic in r-class scalar
/*compute conditional dominance*/
if (strlen(model_specs.cdlcompu) == 0) {
if (strlen(cdlcompu) == 0) {
if (number_of_IVs > 5) printf("\n\n{txt}Computing conditional dominance\n")
Expand All @@ -189,7 +197,7 @@ void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
}
/*compute complete dominance*/
if (strlen(model_specs.cptcompu) == 0) {
if (strlen(cptcompu) == 0) {
if (number_of_IVs > 5) printf("\n{txt}Computing complete dominance\n")
Expand Down Expand Up @@ -239,29 +247,38 @@ void dominance(struct domin_specs scalar model_specs, pointer scalar model_call)
end

/*Mata function to execute 'domin-flavored' models*/
version 12
**# Mata function to execute 'domin-flavored' models
version 12.1

mata:
mata set matastrict on
real scalar domin_call(string scalar mi, string scalar IVs_in_model, real scalar all_subsets_fitstat, real scalar constant_model_fitstat)
real scalar domin_call(string scalar IVs_in_model,
real scalar all_subsets_fitstat, real scalar constant_model_fitstat, ///
struct domin_specs scalar model_specs)
{
real scalar fitstat
if (strlen(mi) == 0) { //if not multiple imputation, then regular regression
if (strlen(model_specs.mi) == 0) { //if not multiple imputation, then regular regression
stata("\`reg' \`dv' \`all' " + IVs_in_model + " [\`weight'\`exp'] if \`touse', \`regopts'", 1) //conduct regression
stata(model_specs.reg + " " + model_specs.dv + " " + ///
model_specs.all + " " + IVs_in_model + " [" + ///
model_specs.weight + model_specs.exp + "] if " +
model_specs.touse + ", " + model_specs.regopts, 1) //conduct regression
fitstat = st_numscalar(st_local("fitstat")) - all_subsets_fitstat - constant_model_fitstat //record fitstat omitting constant and all subsets values; note that the fitstat to be pulled from Stata is stored as the Stata local "fitstat"
}
else { //otherwise, regression with "mi estimate:"
stata("mi estimate, saving(\`mifile', replace) \`miopt': \`reg' \`dv' \`all' " + IVs_in_model + " [\`weight'\`exp'] if \`keep', \`regopts'", 1) //conduct regression with "mi estimate:"
stata("mi estimate, saving(\`mifile', replace) \`miopt': " + ///
model_specs.reg + " " + model_specs.dv + " " + ///
model_specs.all + " " + IVs_in_model + " [" + ///
model_specs.weight + model_specs.exp + "] if " +
model_specs.touse + ", " + model_specs.regopts, 1) //conduct regression with "mi estimate:"
stata("mi_dom, name(\`mifile') fitstat(\`fitstat') list(\`=e(m_est_mi)')", 1) //use built-in program to obtain average fitstat across imputations
Expand All @@ -275,7 +292,7 @@ mata:
end

/*Mata function to execute epsilon-based relative importance*/
**# Mata function to execute epsilon-based relative importance
version 12.1

mata:
Expand Down
Binary file modified lb_dominance.mlib
Binary file not shown.

0 comments on commit a9a20de

Please sign in to comment.