Skip to content

Latin Hypercube Sampling when parameters are defined according to specific probability distributions

3 messages · Nelly Reduan, Bert Gunter, Suzen, Mehmet

#
Thank you very much Rob for your answer. I have some difficulties to understand how to apply my agent-based model to each parameter combination generated by the LHS, in particular when parameters are defined by probability distributions. Indeed, I have multiple parameters in my model: parameters which are defined by a single value (like ?temperature", "pressure?) and parameters which are defined by probability distributions (like ?dispersal distance?). It?s correct for me to treat distance as a class. When all parameters are defined by a single value, I need first to create a data frame in which each column represents a different parameter, and each row represents a different combination of parameter values. Then, I apply my model to each row of the data frame. But, it?s not clear for me how to do this when parameters are defined from probability distributions? In particular, how can I use your code to apply my model to each of the 50 rows of the data frame ?tabLHS?? Given that one row corresponds to one model simulation, I should have a value generated by the LHS for all distance classes at the first line of the data frame.



library(pse)
q <- list("qexp", "qunif", "qunif")
q.arg <- list(list(rate=exponential_rate), list(min=0, max=1),
list(min=0, max=1))
uncoupledLHS <- LHS(model=model_function, input_parameters, N, q, q.arg)
hist(uncoupledLHS$data$dispersal_distance, breaks=10)

tabLHS <- get.data(uncoupledLHS)



Sorry, it?s the first time that I perform a sensitivity analysis using the LHS.


Thank you very much for your time.

Have a nice day

Nell


________________________________
De : Rob C <bertcarnell at gmail.com>
Envoy? : mardi 30 mai 2017 16:26:08
? : Nelly Reduan
Cc : r-help at r-project.org
Objet : Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

Nell,

I still might not be interpreting your question correctly, but I will try.

When you say that the sum of the probabilities of all distance classes
must equal one, I am going to treat distance as a class, instead of as a
continuous variable.

distance_class_probabilities <- c(9, 11, 10, 8.9, 8, 7, 6, 5.8, 5.1,
4, 3.9, 3.7, 3.4, 3.1, 2, 1.9, 1.6, 1.4, 1, 0.9, 0.8, 0.7, 0.4, 0.3,
0.1)/100
sum(distance_class_probabilities)
distance_classes <- factor(paste0("d", 1:25), ordered = TRUE,
levels=paste0("d", 1:25))
input_parameters <- c("dispersal_distance", "temperature", "pressure")
N <- 1000

plot(1:25, distance_class_probabilities, type="h", lwd=5)

set.seed(1)
require(lhs)
X <- randomLHS(N, length(input_parameters))
dimnames(X) <- list(NULL, input_parameters)
Y <- X
Y[,"dispersal_distance"] <-
approx(x=cumsum(distance_class_probabilities), y=1:25,
xout=X[,"dispersal_distance"], method="constant", yleft=0)$y + 1

hist(Y[,"dispersal_distance"], breaks=c(seq(0.5, 25.5, by=1)))
plot(table(distance_classes[Y[,"dispersal_distance"]]))


Is it still a Latin hypercube?

This is a more difficult question.  In some ways, the sample is still a Latin
hypercube since it was drawn that way.  But once the sample has been discretized
into the distance classes, then it loses the latin property of having only one
sample per "row".  It might be close enough for your purposes though.

Rob
On Tue, May 30, 2017 at 10:59 AM, Nelly Reduan <nell.redu at hotmail.fr> wrote:

  
  
#
I think you should take this conversation private or seek local
statistical expertise. This is about strategies for analysis, not
about programming in R.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Wed, May 31, 2017 at 9:49 PM, Nelly Reduan <nell.redu at hotmail.fr> wrote:
#
No it is an R programming questions.  Nelly specifically asked you:

"how can I use your code to apply my model to each of the 50 rows of
the data frame ?tabLHS??"