[R] LHS random number generator

Shah Alam dr@@|@m@o|@ng| @end|ng |rom gm@||@com
Mon Apr 12 14:21:14 CEST 2021


Hello everyone,

I am using the LHS package to generate a combination of a
set of parameter values. However, I am not sure how to fix some parameter
values to 2 decimal points.
For example:

I want to make combinations in such a way that values for parameter
c("lmp", 0.40, 0.43) are taken as 0.40, 0.41, 0.42,0.43.

My codes are:

prior_lhs <- list(c("r_mu", 0.00299, 0.0032),
                  c("r_sd", 0.001, 0.002),
                  c("lmp", 0.40, 0.43),
                  c("gr_mu", 0.14, 0.16),
                  c("gr_sd", 0.01, 0.020),
                  c("alpha1", 0.0001, 0.0018),
                  c("alpha2", 0.0017, 0.0028),
                  c("alpha3", 0.005, 0.009),
                  c("beta", 0.69, 0.75)
)


### Simulation with priors from LHS ####
nb_simul <- 10000
nparam <- length(prior_lhs)
random_tab = randomLHS(nb_simul, nparam)
lhs_index = 1
param <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)

for (i in 1:nb_simul) {
  temp_par <- matrix(rep(0, nparam), nrow = 1, ncol = nparam)
  for (j in 1:nparam) {
    temp_par[j] = as.numeric(prior_lhs[[j]][2]) +
      (as.numeric(prior_lhs[[j]][3]) - as.numeric(prior_lhs[[j]][2])) *
random_tab[lhs_index, j]
  }
  param <- rbind(param, temp_par)
  lhs_index <- lhs_index+1
}
param <- param[-1,]

Best regards,
Shah

	[[alternative HTML version deleted]]



More information about the R-help mailing list