[R] LHS random number generator

Shah Alam dr@@|@m@o|@ng| @end|ng |rom gm@||@com
Tue Apr 13 11:16:22 CEST 2021


Hi Richard and Jim

Thanks for your response. Sorry for the confusion. This is lhs package
(small letters), and after loading the package, I used the function
randomLHS.

The problem remained the same. I am trying to fix the length.out=2 for
lmp=c(0.40, 0.43), and length.out = 4 for all other variables/inputs.

Best regards,
Shah








On Tue, 13 Apr 2021 at 09:02, Jim Lemon <drjimlemon using gmail.com> wrote:

> Hi Shah,
> I think what you are struggling toward is this:
>
> prior_lhs <- list(r_mu=c( 0.00299, 0.0032),
>                   r_sd=c( 0.001, 0.002),
>                   lmp=c( 0.40, 0.43),
>                   gr_mu=c( 0.14, 0.16),
>                   gr_s=c( 0.01, 0.020),
>                   alpha1=c( 0.0001, 0.0018),
>                   alpha2=c(0.0017, 0.0028),
>                   alpha3=c( 0.005, 0.009),
>                   beta=c(0.69, 0.75))
> for(i in 1:length(prior_lhs))
>  prior_lhs[[i]]<-seq(prior_lhs[[i]][1],prior_lhs[[i]][2],length.out=4)
>
> This gives you the "quartiles" you need for randomLHS function in the
> "lhs" package if I read the help page correctly.
>
> Jim
>
> On Mon, Apr 12, 2021 at 10:21 PM Shah Alam <dr.alamsolangi using gmail.com>
> wrote:
> >
> > 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]]
> >
> > ______________________________________________
> > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list