Skip to content

Commit 10f251e

Browse files
author
NightlordTW
committed
replace for loop by vectorized operation
1 parent 1af7f37 commit 10f251e

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

R/RcppExports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ run_simulations_par <- function(nsim, n, muT, muR, SigmaT, SigmaR, lequi_tol, ue
317317
#' @param typey Integer vector indicating the classification of each endpoint, where `1` corresponds to a primary endpoint and `2` corresponds to a secondary endpoint.
318318
#' @param adseq Logical. If `TRUE`, applies sequential (hierarchical) testing.
319319
#' @param k Integer. Minimum number of endpoints required for equivalence.
320-
#' @param arm_seed arma::ivec. Random seed vector (one per simulation).
320+
#' @param arm_seed Integer vector. Random seed for each simulation.
321321
#'
322322
#' @details
323323
#' This function performs equivalence testing using either the Difference of Means (DOM) or Ratio of Means (ROM) approach.

man/run_simulations_2x2.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,15 @@ arma::mat check_equivalence(const arma::uvec& typey,
123123

124124
// If no primary endpoints exist, assume sequential test passes automatically
125125
bool sumpe = (num_primary == 0);
126-
int sumtypey = 0;
126+
int sumtypey = arma::accu(tbioq.cols(arma::find(typey == 1)));
127127

128+
//int sumtypey = 0;
128129
// Count number of primary endpoints that meet equivalence
129-
for (size_t i = 0; i < typey.n_elem; i++) {
130-
if (typey(i) == 1) {
131-
sumtypey += tbioq(0, i);
132-
}
133-
}
130+
//for (size_t i = 0; i < typey.n_elem; i++) {
131+
// if (typey(i) == 1) {
132+
// sumtypey += tbioq(0, i);
133+
// }
134+
//}
134135

135136
// Ensure all primary endpoints pass if sequential testing is enabled
136137
if (num_primary > 0) {
@@ -832,7 +833,7 @@ arma::mat run_simulations_par(const int nsim,
832833
//' @param typey Integer vector indicating the classification of each endpoint, where `1` corresponds to a primary endpoint and `2` corresponds to a secondary endpoint.
833834
//' @param adseq Logical. If `TRUE`, applies sequential (hierarchical) testing.
834835
//' @param k Integer. Minimum number of endpoints required for equivalence.
835-
//' @param arm_seed arma::ivec. Random seed vector (one per simulation).
836+
//' @param arm_seed Integer vector. Random seed for each simulation.
836837
//'
837838
//' @details
838839
//' This function performs equivalence testing using either the Difference of Means (DOM) or Ratio of Means (ROM) approach.
@@ -903,6 +904,7 @@ arma::mat run_simulations_2x2(const int nsim,
903904
return results.t(); // Transpose before returning
904905
}
905906

907+
906908
RCPP_MODULE(test)
907909
{
908910
function("rcpp_test_2x2_dom", &test_2x2_dom);

vignettes/sampleSize_crossover.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ lequi_upper <- c(AUC = log(1.25), Cmax = log(1.25))
4646
list_lequi.tol = list("T_vs_R" = lequi_lower),
4747
list_uequi.tol = list("T_vs_R" = lequi_upper),
4848
dtype = "2x2", ctype = "DOM", lognorm = FALSE,
49-
adjust = "no", ncores = 1, nsim = 10000, seed = 1234))
49+
adjust = "no", ncores = 1, nsim = 5000, seed = 1234))
5050
```
5151
The total sample size required is `r ss$response$n_total` subjects, which corresponds to the estimate obtained using the PASS software (n=37).
5252

0 commit comments

Comments
 (0)