Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-10 Thread S Ellison
> I think that I need to
> draw a Hypercube sample for each age class (i.e., for 0, 1, 2, 3, 4, 5, 6, 7) 
> in a
> given simulation (i.e., N = 1) and the LHS values for all age classes should 
> be
> like the observed cumulative distribution (see attached figure). 
> output of randomLHS should be a matrix with 100 rows (N = 100 simulations)
> and 7 columns (7 age classes) containing LHS values and each row should
> exhibit the same pattern as the observed cumulative distribution.

If you want each row to hold _different_ cumulative probabilities drawn at 
random from something, but broadly following your chosen non-random pattern, it 
sounds like you will need to decide what joint distribution you want to draw 
those probabilities from so that the cumulative 'probability' is strictly 
monotonic. You might then be able to work out how to map the multivariate [0,1] 
output of randomLHS to generate the relevant points. It's possible that a 
simple kludge applied row-wise to [0,1] values might work, but a) I can't think 
of one quickly and b) I'd have a hard time defending it if I did.

It sounds like you need to find a nearby statistician and explain what you are 
trying to achieve. They should be able to tell you either how to get there or, 
perhaps, why it's not sensible to start and what to do instead.  

Sorry I can't help further

S.


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@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.


Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-08 Thread Marine Regis
Thanks for your answer.

I have attached the plot for representing the variable. I think that I need to 
draw a Hypercube sample for each age class (i.e., for 0, 1, 2, 3, 4, 5, 6, 7) 
in a given simulation (i.e., N = 1) and the LHS values for all age classes 
should be like the observed cumulative distribution (see attached figure). 
Thus, the output of randomLHS should be a matrix with 100 rows (N = 100 
simulations) and 7 columns (7 age classes) containing LHS values and each row 
should exhibit the same pattern as the observed cumulative distribution.
With the command “qpois(X[, "mortality_probability"], 0.9)”, I don’t obtain a 
LHS value for each age class and the distribution is not a cumulative 
distribution as in the attached figure. So, I am afraid I don’t know how to do 
that.
Thanks so much for your time
Marine




De : S Ellison 
Envoyé : mardi 8 août 2017 14:48
À : Marine Regis; r-help@r-project.org
Objet : RE: Latin hypercube sampling from a non-uniform distribution

> However, my variable is simulated from the cumulative distribution function
> of the Poisson distribution.
Then I am afraid I don't know what you're trying to achieve.
Or why.

However, the principle holds; write a function that maps [0,1] to the 'pattern' 
you want, do that and apply it to the result from randomLHS.
It happens that for generating data that follow a given probability 
distribution F, that function is the quantile function for F so you often do 
not need to write it.






***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If
you have received this message in error, please notify the sender
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com
and delete this message and any copies from your computer and network.
LGC Limited. Registered in England 2991879.
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
R-help@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.

Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-08 Thread S Ellison
> However, my variable is simulated from the cumulative distribution function
> of the Poisson distribution. 
Then I am afraid I don't know what you're trying to achieve. 
Or why.

However, the principle holds; write a function that maps [0,1] to the 'pattern' 
you want, do that and apply it to the result from randomLHS. 
It happens that for generating data that follow a given probability 
distribution F, that function is the quantile function for F so you often do 
not need to write it.

 




***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@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.


Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-07 Thread Marine Regis
Thanks for your answer.


However, my variable is simulated from the cumulative distribution function of 
the Poisson distribution. So, the pattern obtained from the function "qpois" is 
not the same as the observed pattern (i.e., obtained from the function "ppois")

set.seed(5)
mortality_probability <- round(ppois(seq(0, 7, by = 1), lambda = 0.9), 2)
barplot(mortality_probability, names.arg = seq(0, 7, by = 1), xlab = "Age 
class", ylab = "Probability")

library(lhs)
set.seed(1)
parm <- c("var1", "var2", "mortality_probability")
X <- randomLHS(100, length(parm))
colnames(X) <- c("var1", "var2", "mortality_probability")
X[, "mortality_probability"] <- qpois(X[, "mortality_probability"], 0.9)
hist(X[, "mortality_probability"])


Thanks for your time

Marine





De : S Ellison 
Envoy� : lundi 7 ao�t 2017 14:36
� : Marine Regis; r-help@r-project.org
Objet : RE: Latin hypercube sampling from a non-uniform distribution

> How can I draw a Hypercube sample for the variable  mortality_probability  so
> that this variable exhibits the same pattern as the observed distribution?

One simple way is to use the uniform random output of randomLHS as input to the 
quantile function for your desired distribution(s).

For example:

q <- randomLHS(1000, 3)
colnames(q) <- c("A", "B", "mort")
q[, "mort"] <- qpois(q[,"mort"], 1.5)


S Ellison






***
This email and any attachments are confidential. Any use...{{dropped:11}}

__
R-help@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.

Re: [R] Latin hypercube sampling from a non-uniform distribution

2017-08-07 Thread S Ellison
> How can I draw a Hypercube sample for the variable  mortality_probability  so
> that this variable exhibits the same pattern as the observed distribution?

One simple way is to use the uniform random output of randomLHS as input to the 
quantile function for your desired distribution(s).

For example:

q <- randomLHS(1000, 3)
colnames(q) <- c("A", "B", "mort")
q[, "mort"] <- qpois(q[,"mort"], 1.5)


S Ellison






***
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
__
R-help@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.


[R] Latin hypercube sampling from a non-uniform distribution

2017-08-04 Thread Marine Regis
Hello,

I am performing a sensitivity analysis using a Latin Hypercube sampling. 
However, I have difficulty to draw a Hypercube sample for one variable. I�ve 
generated this variable from a Poisson distribution as follows:

set.seed(5)
mortality_probability <- round(ppois(seq(0, 7, by = 1), lambda = 0.9), 2)
barplot(mortality_probability, names.arg = seq(0, 7, by = 1), xlab = "Age 
class", ylab = "Probability")

How can I draw a Hypercube sample for the variable �mortality_probability� so 
that this variable exhibits the same pattern as the observed distribution?

Here is a reproducible code to draw Hypercube samples (my sensitivity analysis 
includes several parameters and the variables �var1� and �var2� follow a 
uniform distribution):

library(lhs)
set.seed(1)
parm <- c("var1", "var2", "mortality_probability")
X <- randomLHS(100, length(parm))

Any suggestions would be much welcome.

Thanks for your time
Marine


[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-06-01 Thread Suzen, Mehmet
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”?"

__
R-help@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.

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-06-01 Thread Bert Gunter
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.r...@hotmail.fr> wrote:
> 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 <bertcarn...@gmail.com>
> Envoyé : mardi 30 mai 2017 16:26:08
> À : Nelly Reduan
> Cc : r-help@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.r...@hotmail.fr> wrote:
>> Thanks a lot Rob for your answer. I need to add a condition for the
>> parameter “dispersal distance”. The sum of the probabilities of all distance
>> classes must be equal to 1:
>>
>> y <- 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)
>>
>> x <- seq(1, 25, by = 1)
>>
>> barplot(y/100, names.arg=x, ylab="Probability", xlab="Distance (km)")
>>
>>
>>
>> With this con

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-05-31 Thread Nelly Reduan
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 <bertcarn...@gmail.com>
Envoyé : mardi 30 mai 2017 16:26:08
À : Nelly Reduan
Cc : r-help@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.r...@hotmail.fr> wrote:
> Thanks a lot Rob for your answer. I need to add a condition for the
> parameter “dispersal distance”. The sum of the probabilities of all distance
> classes must be equal to 1:
>
> y <- 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)
>
> x <- seq(1, 25, by = 1)
>
> barplot(y/100, names.arg=x, ylab="Probability", xlab="Distance (km)")
>
>
>
> With this condition, is it possible to perform a LHS?
>
> Thanks a lot for your time.
>
> Nell
>
>
> 
> De : R-help <r-help-boun...@r-project.org> de la part de Rob C
> <bertcarn...@gmail.com>
> Envoyé : samedi 27 mai 2017 13:32:23
> À : r-help@r-project.org
> Objet : Re: [R] Latin Hypercube Sampling when parameters are defined
> according to specific probability distributions
>
>>May 26, 2017; 11:41am  Nelly Reduan Latin Hypercube Sampling when
>> parameters are >defined according to specific probability distributions
>>Hello,
>> I would like to perform a sensitivity analysis using a Latin Hypercube
>> Sampling (LHS).
>>Among the input parameters in the model, I have a parameter dispersal
>> distance which is defined according to an exponential probability
>> distribution.
>
>>In the model, the user thus sets a 

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-05-30 Thread Rob C
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.r...@hotmail.fr> wrote:
> Thanks a lot Rob for your answer. I need to add a condition for the
> parameter “dispersal distance”. The sum of the probabilities of all distance
> classes must be equal to 1:
>
> y <- 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)
>
> x <- seq(1, 25, by = 1)
>
> barplot(y/100, names.arg=x, ylab="Probability", xlab="Distance (km)")
>
>
>
> With this condition, is it possible to perform a LHS?
>
> Thanks a lot for your time.
>
> Nell
>
>
> 
> De : R-help <r-help-boun...@r-project.org> de la part de Rob C
> <bertcarn...@gmail.com>
> Envoyé : samedi 27 mai 2017 13:32:23
> À : r-help@r-project.org
> Objet : Re: [R] Latin Hypercube Sampling when parameters are defined
> according to specific probability distributions
>
>>May 26, 2017; 11:41am  Nelly Reduan Latin Hypercube Sampling when
>> parameters are >defined according to specific probability distributions
>>Hello,
>> I would like to perform a sensitivity analysis using a Latin Hypercube
>> Sampling (LHS).
>>Among the input parameters in the model, I have a parameter dispersal
>> distance which is defined according to an exponential probability
>> distribution.
>
>>In the model, the user thus sets a default probability value for each
>> distance class.
>
>>For example, for distances ([0  2]; ]2  4]; ]4  6]; ]6  8]; ]8  10];; ]48
>> 50],
>
>>respective probabilities are 0.055; 0.090; 0.065; 0.035; 0.045;; 0.005.
>
>  >Here is the code to represent an exponential probability
> distribution for the parameter dispersal distance:
>
>>set.seed(0)
>>foo <- rexp(100, rate = 1/10)
>>hist(foo, prob=TRUE, breaks=20, ylim=c(0,0.1), xlab ="Distance (km)")
>>lines(dexp(seq(1, 100, by = 1), rate = 1/mean(foo)),col="red")
>>1/mean(foo)
>
>>When a parameter is defined according to a specific probability
>> distribution, how can I perform a LHS ?
>>For example, should I sample N values from a uniform distribution for each
>> distance class (i.e., [0 � 2]; ]2 � 4]; ]4 � 6]; ]6 � 8]; ]8 � 10];��; ]48 �
>> 50])
>>or sample N values from exponential distributions with different rates ?
>
>>Here is the code used to perform a LHS when the parameter �dispersal
>> distance� is defined by one default value in the model:
>
>>library(pse)
>>factors <- c("distance")
>>q <- c("qexp")
>>q.arg <- list( list(rate=1/30) )
>>uncoupledLHS <- LHS(model=NULL, factors, 50, q, q.arg)
>>head(uncoupledLHS)
>
>>Thanks a lot for your time.
>>Have a nice day
>>Nell
>
> Nell,
>
> I would like to suggest a slightly different method for generating the
> sample using the lhs library,  then I will try using the pse library.
> Generally when you have a package specific
> question, you should try to contact the package maintainer first.
>
> set.seed(1)
> # I don't think your model has only one parameter, so I will include
> multiple
> input_parameters <- c(&qu

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-05-30 Thread Nelly Reduan
Thanks a lot Rob for your answer. I need to add a condition for the parameter 
“dispersal distance”. The sum of the probabilities of all distance classes must 
be equal to 1:

y <- 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)

x <- seq(1, 25, by = 1)

barplot(y/100, names.arg=x, ylab="Probability", xlab="Distance (km)")



With this condition, is it possible to perform a LHS?

Thanks a lot for your time.

Nell



De : R-help <r-help-boun...@r-project.org> de la part de Rob C 
<bertcarn...@gmail.com>
Envoyé : samedi 27 mai 2017 13:32:23
À : r-help@r-project.org
Objet : Re: [R] Latin Hypercube Sampling when parameters are defined according 
to specific probability distributions

>May 26, 2017; 11:41am  Nelly Reduan Latin Hypercube Sampling when parameters 
>are >defined according to specific probability distributions
>Hello,
> I would like to perform a sensitivity analysis using a Latin Hypercube 
> Sampling (LHS).
>Among the input parameters in the model, I have a parameter dispersal distance 
>which is defined according to an exponential probability distribution.

>In the model, the user thus sets a default probability value for each distance 
>class.

>For example, for distances ([0  2]; ]2  4]; ]4  6]; ]6  8]; ]8  10];; ]48  50],

>respective probabilities are 0.055; 0.090; 0.065; 0.035; 0.045;; 0.005.

 >Here is the code to represent an exponential probability
distribution for the parameter dispersal distance:

>set.seed(0)
>foo <- rexp(100, rate = 1/10)
>hist(foo, prob=TRUE, breaks=20, ylim=c(0,0.1), xlab ="Distance (km)")
>lines(dexp(seq(1, 100, by = 1), rate = 1/mean(foo)),col="red")
>1/mean(foo)

>When a parameter is defined according to a specific probability distribution, 
>how can I perform a LHS ?
>For example, should I sample N values from a uniform distribution for each 
>distance class (i.e., [0 � 2]; ]2 � 4]; ]4 � 6]; ]6 � 8]; ]8 � 10];��; ]48 � 
>50])
>or sample N values from exponential distributions with different rates ?

>Here is the code used to perform a LHS when the parameter �dispersal distance� 
>is defined by one default value in the model:

>library(pse)
>factors <- c("distance")
>q <- c("qexp")
>q.arg <- list( list(rate=1/30) )
>uncoupledLHS <- LHS(model=NULL, factors, 50, q, q.arg)
>head(uncoupledLHS)

>Thanks a lot for your time.
>Have a nice day
>Nell

Nell,

I would like to suggest a slightly different method for generating the
sample using the lhs library,  then I will try using the pse library.
Generally when you have a package specific
question, you should try to contact the package maintainer first.

set.seed(1)
# I don't think your model has only one parameter, so I will include multiple
input_parameters <- c("dispersal_distance", "temperature", "pressure")
N <- 50
exponential_rate <- 1/30

library(lhs)
X <- randomLHS(N, length(input_parameters))
dimnames(X) <- list(NULL, input_parameters)
# X is now a uniformly distributed Latin hypercube
head(X)
hist(X[,1], breaks=5)
hist(X[,2], breaks=5)
hist(X[,3], breaks=5)
# now, transform the dispersal_distance paramter to an exponential sample
Y <- X
Y[,"dispersal_distance"] <- qexp(X[,"dispersal_distance"],
rate=exponential_rate)
hist(Y[,1], breaks=10)
# you can transform the other marginals as required and then assess
function sensitivity
model_function <- function(z) z[1]*z[2] + z[3]
apply(Y, 1, model_function)

# now, trying to use pse
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)

Rob

__
R-help@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]]

__
R-help@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.

Re: [R] Latin Hypercube Sampling when parameters are defined according to specific probability distributions

2017-05-27 Thread Rob C
>May 26, 2017; 11:41am  Nelly Reduan Latin Hypercube Sampling when parameters 
>are >defined according to specific probability distributions
>Hello,
> I would like to perform a sensitivity analysis using a Latin Hypercube 
> Sampling (LHS).
>Among the input parameters in the model, I have a parameter dispersal distance 
>which is defined according to an exponential probability distribution.

>In the model, the user thus sets a default probability value for each distance 
>class.

>For example, for distances ([0  2]; ]2  4]; ]4  6]; ]6  8]; ]8  10];; ]48  50],

>respective probabilities are 0.055; 0.090; 0.065; 0.035; 0.045;; 0.005.

 >Here is the code to represent an exponential probability
distribution for the parameter dispersal distance:

>set.seed(0)
>foo <- rexp(100, rate = 1/10)
>hist(foo, prob=TRUE, breaks=20, ylim=c(0,0.1), xlab ="Distance (km)")
>lines(dexp(seq(1, 100, by = 1), rate = 1/mean(foo)),col="red")
>1/mean(foo)

>When a parameter is defined according to a specific probability distribution, 
>how can I perform a LHS ?
>For example, should I sample N values from a uniform distribution for each 
>distance class (i.e., [0 � 2]; ]2 � 4]; ]4 � 6]; ]6 � 8]; ]8 � 10];��; ]48 � 
>50])
>or sample N values from exponential distributions with different rates ?

>Here is the code used to perform a LHS when the parameter �dispersal distance� 
>is defined by one default value in the model:

>library(pse)
>factors <- c("distance")
>q <- c("qexp")
>q.arg <- list( list(rate=1/30) )
>uncoupledLHS <- LHS(model=NULL, factors, 50, q, q.arg)
>head(uncoupledLHS)

>Thanks a lot for your time.
>Have a nice day
>Nell

Nell,

I would like to suggest a slightly different method for generating the
sample using the lhs library,  then I will try using the pse library.
Generally when you have a package specific
question, you should try to contact the package maintainer first.

set.seed(1)
# I don't think your model has only one parameter, so I will include multiple
input_parameters <- c("dispersal_distance", "temperature", "pressure")
N <- 50
exponential_rate <- 1/30

library(lhs)
X <- randomLHS(N, length(input_parameters))
dimnames(X) <- list(NULL, input_parameters)
# X is now a uniformly distributed Latin hypercube
head(X)
hist(X[,1], breaks=5)
hist(X[,2], breaks=5)
hist(X[,3], breaks=5)
# now, transform the dispersal_distance paramter to an exponential sample
Y <- X
Y[,"dispersal_distance"] <- qexp(X[,"dispersal_distance"],
rate=exponential_rate)
hist(Y[,1], breaks=10)
# you can transform the other marginals as required and then assess
function sensitivity
model_function <- function(z) z[1]*z[2] + z[3]
apply(Y, 1, model_function)

# now, trying to use pse
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)

Rob

__
R-help@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.

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

2017-05-26 Thread Nelly Reduan
Hello,

 I would like to perform a sensitivity analysis using a Latin Hypercube 
Sampling (LHS).

Among the input parameters in the model, I have a parameter �dispersal 
distance� which is defined according to an exponential probability distribution.

In the model, the user thus sets a default probability value for each distance 
class.

For example, for distances ([0 � 2]; ]2 � 4]; ]4 � 6]; ]6 � 8]; ]8 � 10];��; 
]48 � 50],

respective probabilities are 0.055; 0.090; 0.065; 0.035; 0.045;���; 0.005.

 Here is the code to represent an exponential probability distribution for the 
parameter �dispersal distance�:

set.seed(0)
foo <- rexp(100, rate = 1/10)
hist(foo, prob=TRUE, breaks=20, ylim=c(0,0.1), xlab ="Distance (km)")
lines(dexp(seq(1, 100, by = 1), rate = 1/mean(foo)),col="red")
1/mean(foo)

When a parameter is defined according to a specific probability distribution, 
how can I perform a LHS ?
For example, should I sample N values from a uniform distribution for each 
distance class (i.e., [0 � 2]; ]2 � 4]; ]4 � 6]; ]6 � 8]; ]8 � 10];��; ]48 � 
50])
or sample N values from exponential distributions with different rates ?

Here is the code used to perform a LHS when the parameter �dispersal distance� 
is defined by  one default value in the model:

 library(pse)

factors <- c("distance")

q <- c("qexp")

q.arg <- list( list(rate=1/30) )

uncoupledLHS <- LHS(model=NULL, factors, 50, q, q.arg)

head(uncoupledLHS)

Thanks a lot for your time.
Have a nice day
Nell



[[alternative HTML version deleted]]

__
R-help@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.

[R] latin hypercube sampling

2013-02-19 Thread Aimee Kopolow
Hi all,

I am attempting to use latin hypercube sampling to sample different
variable functions in a series of simultaneous differential equations.
There is very little code online about lhs or clhs, so from different
other help threads I have seen, it seems I need to create a
probability density function for each variable function, and then use
latin hypercube sampling on this pdf.

So far, I have created a data frame consisting of the y output of
density(functionX) for each of the different functions I wish to
sample. [examples of functions include T1(t), WL1(T1,t),
BE1(WL1,T1,t)] The dataframe consists of 512 rows/vectors for each
function.



I tried running
res - clhs(df, size = 500, iter = 2000, progress = FALSE, simple = TRUE)


and it returned a single series of 500 samples, rather than a series
of 500 samples per function.

I ultimately need a sample of each variable function that I can run
through my model, putting each individual variable function as a
constant instead, and then performing PRCC. Is there anyone who can
advise on how to do this, or failing that, where I should look for
sample code?

Thank you for any help you are able to give,
Aimee.

__
R-help@r-project.org mailing list
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.


Re: [R] latin hypercube sampling

2013-02-19 Thread Rob Carnell
Aimee Kopolow alj27 at georgetown.edu writes:
 
 Hi all,
 
 I am attempting to use latin hypercube sampling to sample different
 variable functions in a series of simultaneous differential equations.
 There is very little code online about lhs or clhs, so from different
 other help threads I have seen, it seems I need to create a
 probability density function for each variable function, and then use
 latin hypercube sampling on this pdf.
 
 So far, I have created a data frame consisting of the y output of
 density(functionX) for each of the different functions I wish to
 sample. [examples of functions include T1(t), WL1(T1,t),
 BE1(WL1,T1,t)] The dataframe consists of 512 rows/vectors for each
 function.
 
 I tried running
 res - clhs(df, size = 500, iter = 2000, progress = FALSE, simple = TRUE)
 
 and it returned a single series of 500 samples, rather than a series
 of 500 samples per function.
 
 I ultimately need a sample of each variable function that I can run
 through my model, putting each individual variable function as a
 constant instead, and then performing PRCC. Is there anyone who can
 advise on how to do this, or failing that, where I should look for
 sample code?
 
 Thank you for any help you are able to give,
 Aimee.
 
 

Aimee,

I'm the package maintainer for the lhs package.  Unfortunately, I'm not familiar
with the functions you mentioned (reproducible code would help us answer your
post).  I will try to show something parallel to what you described.

require(lhs)

# functions you described
T1 - function(t) t*t
WL1 - function(T1, t) T1*t
BE1 - function(WL1, T1, t) WL1*T1*t

# t is distributed according to some pdf (e.g. normal)
require(lhs)
# draw a lhs with 512 rows and 3 columns (one for each function)
y - randomLHS(512, 3)
# transform the three columns to a normal distribution (these could be any
# distribution)
t - apply(y, 2, function(columny) qnorm(columny, 2, 1))
# transform t using the functions provided
result - cbind(
  T1(t[,1]),
  WL1(T1(t[,2]), t[,2]),
  BE1(WL1(T1(t[,3]), t[,3]), T1(t[,3]), t[,3])
)
# check the results
# these should be approximately uniform
windows()
par(mfrow=c(2,2))
apply(y, 2, hist, breaks=50)
# these should be approximately normal
windows()
par(mfrow=c(2,2))
apply(t, 2, hist, breaks=50)
# these should be the results of the functions
windows()
par(mfrow=c(2,2))
apply(result, 2, hist, breaks=50)

Please feel free to contact me as the package maintainer if you need additional
help with lhs.

Rob

__
R-help@r-project.org mailing list
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.


Re: [R] Latin Hypercube Sampling with a condition

2011-06-02 Thread Rob Carnell
Duarte Viana viana.sptd at gmail.com writes:

 
 Hello all,
 
 I am trying to do a Latin Hypercube Sampling (LHS) to a 5-parameter
 design matrix. I start as follows:
 
 library(lhs)
 
 p1-randomLHS(1000, 5)
 
 If I check the distribution of each parameter (column), they are
 perfectly uniformly distributed (as expected).For example,
 
 hist(p1[,1])
 
 Now the hard (maybe strange) question. I want the combination of the
 first three parameters to sum up to 1 (which obviously do not)
 
 s-p1[,1]+p1[,2]+p1[,3]
 
 s==1
 
 It occurred to me to divide each of these parameters with the sum
 (vector s above). However the uniform distribution is lost (example
 for parameter 1 - first column):
 
 par1.transf-p1[,1]/s
 
 hist(par1.transf)
 
 So, is there a way to maintain the random LHS (with uniformly
 distributed parameters) so that the refered condition is fulfilled?
 
 Any suggestions would be much welcome.
 
 Thanks,
 
 Duarte
 
 

Duarte,

In my experience with Latin hypercube samples, most people draw the sample on 
a uniform hypercube and then transform the uniform cube to have new 
distributions on the margins.  The transformed distributions are not 
necessarily uniform.  It is possible to draw a Latin hypercube with correlated 
margins and I hope to add that to my package in the future.  I have also done 
transforms such that the transformed marginal distributions are correlated (as 
you have in your example).  I have not seen a correlated set of uniform 
marginal distributions such that the margins sum to one, however.  I'll make a 
quick example argument that explains the difficulty...

In two dimensions, you could draw this which is uniform and correlated.
x - seq(0.05, 0.95, length=10)
y - 1-x
all.equal(x+y, rep(1, length(x)))
hist(x)
hist(y)

But in three dimensions, it is hard to maintain uniformity because large 
samples on the first uniform margin overweight the small samples on the other 
margins.
x - seq(0.05, 0.95, length=10)
y - runif(length(x), 0, 1-x)
z - 1-x-y
hist(x)
hist(y)
hist(z)

If you could explain why you want to maintain the uniformity on the margins, I 
might be able to suggest something different.

Rob

__
R-help@r-project.org mailing list
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.


Re: [R] Latin Hypercube Sampling with a condition

2011-06-02 Thread Ravi Varadhan
I am not sure, but this thread from a couple of months ago might be relevant 
(and useful):

https://stat.ethz.ch/pipermail/r-help/2011-March/273423.html

Ravi.


From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of 
Rob Carnell [carne...@battelle.org]
Sent: Thursday, June 02, 2011 8:30 AM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] Latin Hypercube Sampling with a condition

Duarte Viana viana.sptd at gmail.com writes:


 Hello all,

 I am trying to do a Latin Hypercube Sampling (LHS) to a 5-parameter
 design matrix. I start as follows:

 library(lhs)

 p1-randomLHS(1000, 5)

 If I check the distribution of each parameter (column), they are
 perfectly uniformly distributed (as expected).For example,

 hist(p1[,1])

 Now the hard (maybe strange) question. I want the combination of the
 first three parameters to sum up to 1 (which obviously do not)

 s-p1[,1]+p1[,2]+p1[,3]

 s==1

 It occurred to me to divide each of these parameters with the sum
 (vector s above). However the uniform distribution is lost (example
 for parameter 1 - first column):

 par1.transf-p1[,1]/s

 hist(par1.transf)

 So, is there a way to maintain the random LHS (with uniformly
 distributed parameters) so that the refered condition is fulfilled?

 Any suggestions would be much welcome.

 Thanks,

 Duarte



Duarte,

In my experience with Latin hypercube samples, most people draw the sample on
a uniform hypercube and then transform the uniform cube to have new
distributions on the margins.  The transformed distributions are not
necessarily uniform.  It is possible to draw a Latin hypercube with correlated
margins and I hope to add that to my package in the future.  I have also done
transforms such that the transformed marginal distributions are correlated (as
you have in your example).  I have not seen a correlated set of uniform
marginal distributions such that the margins sum to one, however.  I'll make a
quick example argument that explains the difficulty...

In two dimensions, you could draw this which is uniform and correlated.
x - seq(0.05, 0.95, length=10)
y - 1-x
all.equal(x+y, rep(1, length(x)))
hist(x)
hist(y)

But in three dimensions, it is hard to maintain uniformity because large
samples on the first uniform margin overweight the small samples on the other
margins.
x - seq(0.05, 0.95, length=10)
y - runif(length(x), 0, 1-x)
z - 1-x-y
hist(x)
hist(y)
hist(z)

If you could explain why you want to maintain the uniformity on the margins, I
might be able to suggest something different.

Rob

__
R-help@r-project.org mailing list
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.
__
R-help@r-project.org mailing list
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.


[R] Latin Hypercube Sampling with a condition

2011-06-02 Thread Duarte Viana
Thanks Rob and Ravi for the replies.

Let me try to explain my problem. I am trying to make a kind of
sensitivity analysis where I have 5 parameters (the margins of the
Latin hypercube), 3 of them are proportions that should sum to one. My
idea is to obtain uniform combinations of the 3 proportion-parameters
with the other two parameters. The uniformity should be maintained in
order to guarantee that each parameter (out of 5) have its own range
of values equally represented (for model output analyses).

Theoretically the 3 proportion-parameters might be regarded as one in
which the configuration of the proportions that sum to one vary. I
think I can visualize it like a set of permutations, more or less like
in the example below:

0.1 - 0.1 - 0.8
0.1 - 0.2 - 0.7
0.1 - 0.3 - 0.6
.
.
.
0.1 - 0.1 - 0.8
0.2 - 0.1 - 0.7
0.3 - 0.1 - 0.6
.
.
.
0.8 - 0.1 - 0.1
0.7 - 0.2 - 0.1
0.6 - 0.3 - 0.1
.
.
.
and so on, until all possible combinations are represented (and doing
it with more values) and then combined with the other two parameters
as to form a Latin hypercube.

The solutions given in the thread sent by Ravi work fine for random
generation of the 3 proportion-parameters, but it is hard to make a
Latin hypercube out of that with two more parameters.


Cheers,

Duarte

__
R-help@r-project.org mailing list
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.


Re: [R] Latin Hypercube Sampling with a condition

2011-06-02 Thread Rob Carnell
Duarte Viana viana.sptd at gmail.com writes:

 
 Thanks Rob and Ravi for the replies.
 
 Let me try to explain my problem. I am trying to make a kind of
 sensitivity analysis where I have 5 parameters (the margins of the
 Latin hypercube), 3 of them are proportions that should sum to one. My
 idea is to obtain uniform combinations of the 3 proportion-parameters
 with the other two parameters. The uniformity should be maintained in
 order to guarantee that each parameter (out of 5) have its own range
 of values equally represented (for model output analyses).
 
 Theoretically the 3 proportion-parameters might be regarded as one in
 which the configuration of the proportions that sum to one vary. I
 think I can visualize it like a set of permutations, more or less like
 in the example below:
 
 0.1 - 0.1 - 0.8
 0.1 - 0.2 - 0.7
 0.1 - 0.3 - 0.6
 .
 .
 .
 0.1 - 0.1 - 0.8
 0.2 - 0.1 - 0.7
 0.3 - 0.1 - 0.6
 .
 .
 .
 0.8 - 0.1 - 0.1
 0.7 - 0.2 - 0.1
 0.6 - 0.3 - 0.1
 .
 .
 .
 and so on, until all possible combinations are represented (and doing
 it with more values) and then combined with the other two parameters
 as to form a Latin hypercube.
 
 The solutions given in the thread sent by Ravi work fine for random
 generation of the 3 proportion-parameters, but it is hard to make a
 Latin hypercube out of that with two more parameters.
 
 Cheers,
 
 Duarte
 
 

Duarte,

The commmon practice in your situation is draw the K parameters together as a 
uniform Latin hypercube on 0-1 and then transform the margins of the hypercube 
to the desired distributions.

Easy Example
Parameter 1: normal(1, 2)
Parameter 2: normal(3, 4)
Parameter 3: uniform(5, 10)

require(lhs)
N - 1000
x - randomLHS(N, 3)
y - x
y[,1] - qnorm(x[,1], 1, 2)
y[,2] - qnorm(x[,2], 3, 4)
y[,3] - qunif(x[,3], 5, 10)

par(mfrow=c(2,2))
apply(x, 2, hist)

par(mfrow=c(2,2))
apply(y, 2, hist)

The transformed distributions maintain their Latin properties, but are in 
the form of new distributions.

In your case, you'd like the first three columns to be transformed into a 
correlated set that sums to one.  Still follow the pattern...

x - randomLHS(N, 5)
y - x
y[,1] - x[,1]/rowSums(x[,1:3])
y[,2] - x[,2]/rowSums(x[,1:3])
y[,3] - x[,3]/rowSums(x[,1:3])
y[,4] - x[,4]
y[,5] - x[,5]

par(mfrow=c(2,3))
apply(x, 2, hist)

par(mfrow=c(2,3))
apply(y, 2, hist)

all.equal(rowSums(y[,1:3]), rep(1, nrow(y)))

The uniform properties are gone as you can see here...

par(mfrow=c(1,1))
pairs(x)
paris(y, col=red)

But, the Latin properties of the first three margins are maintained as in 
this smaller example...

N - 10
x - randomLHS(N, 5)
y - x
y[,1] - x[,1]/rowSums(x[,1:3])
y[,2] - x[,2]/rowSums(x[,1:3])
y[,3] - x[,3]/rowSums(x[,1:3])
y[,4] - x[,4]
y[,5] - x[,5]

pairs(x)
pairs(y, col=red)

You could also look into a dirichlet type transform as I posted here
http://tolstoy.newcastle.edu.au/R/e5/help/08/11/8420.html

Rob

__
R-help@r-project.org mailing list
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.


Re: [R] Latin Hypercube Sampling with a condition

2011-06-02 Thread Duarte Viana
Thanks again Rob for your help.

In terms of parameter comparison there won't be a problem. However, if
one wants to assume a particular distribution (and not the one given
by the imposed condition), for example an uniform distribution to
obtain all the possible combinations (all the multidimensional space
uniformly filled), then a limitation exists. Perhaps it is not
possible to fulfill the three criteria - sum to one, maintain the
uniform distribution and maintain the latin hypercube property. Well,
I will try to do it the way you proposed.

Cheers,

Duarte






On Thu, Jun 2, 2011 at 7:06 PM, Rob Carnell carne...@battelle.org wrote:
 Duarte Viana viana.sptd at gmail.com writes:


 Thanks Rob and Ravi for the replies.

 Let me try to explain my problem. I am trying to make a kind of
 sensitivity analysis where I have 5 parameters (the margins of the
 Latin hypercube), 3 of them are proportions that should sum to one. My
 idea is to obtain uniform combinations of the 3 proportion-parameters
 with the other two parameters. The uniformity should be maintained in
 order to guarantee that each parameter (out of 5) have its own range
 of values equally represented (for model output analyses).

 Theoretically the 3 proportion-parameters might be regarded as one in
 which the configuration of the proportions that sum to one vary. I
 think I can visualize it like a set of permutations, more or less like
 in the example below:

 0.1 - 0.1 - 0.8
 0.1 - 0.2 - 0.7
 0.1 - 0.3 - 0.6
 .
 .
 .
 0.1 - 0.1 - 0.8
 0.2 - 0.1 - 0.7
 0.3 - 0.1 - 0.6
 .
 .
 .
 0.8 - 0.1 - 0.1
 0.7 - 0.2 - 0.1
 0.6 - 0.3 - 0.1
 .
 .
 .
 and so on, until all possible combinations are represented (and doing
 it with more values) and then combined with the other two parameters
 as to form a Latin hypercube.

 The solutions given in the thread sent by Ravi work fine for random
 generation of the 3 proportion-parameters, but it is hard to make a
 Latin hypercube out of that with two more parameters.

 Cheers,

 Duarte



 Duarte,

 The commmon practice in your situation is draw the K parameters together as a
 uniform Latin hypercube on 0-1 and then transform the margins of the hypercube
 to the desired distributions.

 Easy Example
 Parameter 1: normal(1, 2)
 Parameter 2: normal(3, 4)
 Parameter 3: uniform(5, 10)

 require(lhs)
 N - 1000
 x - randomLHS(N, 3)
 y - x
 y[,1] - qnorm(x[,1], 1, 2)
 y[,2] - qnorm(x[,2], 3, 4)
 y[,3] - qunif(x[,3], 5, 10)

 par(mfrow=c(2,2))
 apply(x, 2, hist)

 par(mfrow=c(2,2))
 apply(y, 2, hist)

 The transformed distributions maintain their Latin properties, but are in
 the form of new distributions.

 In your case, you'd like the first three columns to be transformed into a
 correlated set that sums to one.  Still follow the pattern...

 x - randomLHS(N, 5)
 y - x
 y[,1] - x[,1]/rowSums(x[,1:3])
 y[,2] - x[,2]/rowSums(x[,1:3])
 y[,3] - x[,3]/rowSums(x[,1:3])
 y[,4] - x[,4]
 y[,5] - x[,5]

 par(mfrow=c(2,3))
 apply(x, 2, hist)

 par(mfrow=c(2,3))
 apply(y, 2, hist)

 all.equal(rowSums(y[,1:3]), rep(1, nrow(y)))

 The uniform properties are gone as you can see here...

 par(mfrow=c(1,1))
 pairs(x)
 paris(y, col=red)

 But, the Latin properties of the first three margins are maintained as in
 this smaller example...

 N - 10
 x - randomLHS(N, 5)
 y - x
 y[,1] - x[,1]/rowSums(x[,1:3])
 y[,2] - x[,2]/rowSums(x[,1:3])
 y[,3] - x[,3]/rowSums(x[,1:3])
 y[,4] - x[,4]
 y[,5] - x[,5]

 pairs(x)
 pairs(y, col=red)

 You could also look into a dirichlet type transform as I posted here
 http://tolstoy.newcastle.edu.au/R/e5/help/08/11/8420.html

 Rob

 __
 R-help@r-project.org mailing list
 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.


__
R-help@r-project.org mailing list
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.


[R] Latin Hypercube Sampling with a condition

2011-05-31 Thread Duarte Viana
Hello all,

I am trying to do a Latin Hypercube Sampling (LHS) to a 5-parameter
design matrix. I start as follows:

library(lhs)

p1-randomLHS(1000, 5)

If I check the distribution of each parameter (column), they are
perfectly uniformly distributed (as expected).For example,

hist(p1[,1])

Now the hard (maybe strange) question. I want the combination of the
first three parameters to sum up to 1 (which obviously do not)

s-p1[,1]+p1[,2]+p1[,3]

s==1

It occurred to me to divide each of these parameters with the sum
(vector s above). However the uniform distribution is lost (example
for parameter 1 - first column):

par1.transf-p1[,1]/s

hist(par1.transf)


So, is there a way to maintain the random LHS (with uniformly
distributed parameters) so that the refered condition is fulfilled?

Any suggestions would be much welcome.

Thanks,

Duarte

__
R-help@r-project.org mailing list
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.