Skip to content

Commit

Permalink
update some files
Browse files Browse the repository at this point in the history
  • Loading branch information
saudiwin committed Dec 16, 2024
1 parent 894096a commit 9174927
Show file tree
Hide file tree
Showing 9 changed files with 738 additions and 35 deletions.
14 changes: 10 additions & 4 deletions inst/stan_files/chunks/id_params.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,31 @@ Chop up the parameter vector to be identified
By constraining two parameters to almost-fixed values (very low SD)
*/
real id_params(vector p, array[] int high, array[] int low,
real fix_high,
real fix_low,
array[] real fix_high,
array[] real fix_low,
real sd_fix_high,
real sd_fix_low,
real mean_val,
real sd_val) {

int N = num_elements(p);
real prob_dens = 0; // hold the calculated probability density
int fix_high_count = 1;
int fix_low_count = 1;

for(n in 1:N) {

if(r_in(n,high)) {

prob_dens += normal_lpdf(p[n]|fix_high,sd_fix_high);
prob_dens += normal_lpdf(p[n]|fix_high[fix_high_count],sd_fix_high);

fix_high_count = fix_high_count + 1;

} else if(r_in(n,low)) {

prob_dens += normal_lpdf(p[n]|fix_low,sd_fix_low);
prob_dens += normal_lpdf(p[n]|fix_low[fix_low_count],sd_fix_low);

fix_low_count = fix_low_count + 1;

} else {

Expand Down
4 changes: 2 additions & 2 deletions inst/stan_files/chunks/id_params2.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Chop up the parameter vector to be identified
By constraining two parameters to almost-fixed values (very low SD)
*/
real id_params2(vector p, array[] int high, array[] int low,
real fix_high,
real fix_low,
array[] real fix_high,
array[] real fix_low,
real sd_fix_high,
real sd_fix_low,
real mean_val,
Expand Down
20 changes: 12 additions & 8 deletions inst/stan_files/chunks/map_func.stan
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ real partial_sum(array[,] int y_slice,
array[] int restrict_high,
array[] int restrict_low,
int center_cutoff,
real fix_high,
real fix_low,
array[] real fix_high,
array[] real fix_low,
real restrict_sd_high,
real restrict_sd_low,
real discrim_reg_upb,
Expand Down Expand Up @@ -133,34 +133,38 @@ real partial_sum(array[,] int y_slice,

// ID parameters

int to_fix_high = r_in(s, restrict_high);
int to_fix_low = r_in(s, restrict_low);


if(const_type == 1 && S_type == 1) {
if(pos_discrim == 0) {
if(r_in(s, restrict_high)) {

if(to_fix_high>0) {
if(time_proc == 2) {
real term = normal_lpdf(L_tp1_var[1, s] | fix_high, restrict_sd_high);
real term = normal_lpdf(L_tp1_var[1, s] | fix_high[to_fix_high], restrict_sd_high);
log_prob += term;
if(debug_mode == 1) print("Added normal_lpdf(L_tp1_var[1,s] | fix_high, restrict_sd_high) to log_prob: ", term);

term = normal_lpdf(L_full[s] | 0, legis_sd);
log_prob += term;
if(debug_mode == 1) print("Added normal_lpdf(L_full[s] | 0, legis_sd) to log_prob: ", term);
} else {
real term = normal_lpdf(L_full[s] | fix_high, restrict_sd_high);
real term = normal_lpdf(L_full[s] | fix_high[to_fix_high], restrict_sd_high);
log_prob += term;
if(debug_mode == 1) print("Added normal_lpdf(L_full[s] | fix_high, restrict_sd_high) to log_prob: ", term);
}
} else if(r_in(s, restrict_low)) {
} else if(to_fix_low>0) {
if(time_proc == 2) {
real term = normal_lpdf(L_tp1_var[1, s] | fix_low, restrict_sd_low);
real term = normal_lpdf(L_tp1_var[1, s] | fix_low[to_fix_low], restrict_sd_low);
log_prob += term;
if(debug_mode == 1) print("Added normal_lpdf(L_tp1_var[1, s] | fix_low, restrict_sd_low) to log_prob: ", term);

term = normal_lpdf(L_full[s] | 0, legis_sd);
log_prob += term;
if(debug_mode == 1) print("Added normal_lpdf(L_full[s] | 0, legis_sd) to log_prob: ", term);
} else {
real term = normal_lpdf(L_full[s] | fix_low, restrict_sd_low);
real term = normal_lpdf(L_full[s] | fix_low[to_fix_low], restrict_sd_low);
log_prob += term;
if(debug_mode == 1) print("Added normal_lpdf(L_full[s] | fix_low, restrict_sd_low) to log_prob: ", term);
}
Expand Down
13 changes: 0 additions & 13 deletions inst/stan_files/chunks/r_in.stan

This file was deleted.

7 changes: 3 additions & 4 deletions inst/stan_files/irt_standard_map.stan
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ functions {
return sum( (alpha - 1) .* log(x) + (beta - 1) .* log1m(x) - vec_offset - vec_lbeta);
}

// #include /chunks/r_in.stan
int r_in(int pos,array[] int pos_var) {

for (p in 1:(size(pos_var))) {
if (pos_var[p]==pos) {
// can return immediately, as soon as find a match
return 1;
return p;
}
}
return 0;
Expand Down Expand Up @@ -91,8 +90,8 @@ data {
int num_restrict_low; // number of items/persons constrained to be low
array[num_restrict_high] int restrict_high; // position of high valued fixed parameter
array[num_restrict_low] int restrict_low; // position of low valued fixed parameter
real fix_high; // value to fix high parameter to
real fix_low; // value to fix low parameter to
array[num_restrict_high] real fix_high; // value to fix high parameter to
array[num_restrict_high] real fix_low; // value to fix low parameter to
real discrim_reg_upb;
real discrim_reg_lb;
real discrim_miss_upb;
Expand Down
6 changes: 4 additions & 2 deletions man/id_estimate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/id_plot_legis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9174927

Please sign in to comment.