0

Is there an R package or functions which can generate a random field with truncated distributions?

I am trying to simulate a lognormal spatial random field but I need the simulated value in a certain range. So I need some easy to use functions to generate a truncated Gaussian field to start with. To be specific, I need a function like GaussRF from the RandomFields package or grf from the geoR package to generate a random field with truncated marginal distributions and a correlation structure with a specified range direclty.

If there is no availabe read-to-use functions or packages,is it possible that I write my own very easily?

www
  • 38,575
  • 12
  • 48
  • 84
Zhenglei
  • 988
  • 1
  • 10
  • 21
  • 1
    Welcome to StackOverflow! Could you make a more specific example? For instance, are you looking for a function analogous to `rlnorm` that instead returns a random number from a truncated log-normal instead of a log-normal? Or are you looking for an analogue to `dlnorm` (the density function)? – David Robinson Nov 06 '12 at 16:29
  • @DavidRobinson thanks for the quick reply. No, I am not looking for a function to generate a truncated distribution, but a function like `GaussRF` in the RandomFieds package to generate a truancated random field directly. – Zhenglei Nov 06 '12 at 16:45
  • 2
    You need to explain why you cannot simply truncate a (non-truncated) random field at the bounds of your specification. This is known as "rejection sampling". – IRTFM Nov 06 '12 at 17:21
  • To add to DWin's comment: if you can write the distribution function, you can easily use it as the weighting function argument `prob` in the function `sample` . – Carl Witthoft Nov 06 '12 at 18:32
  • 1
    this doesn't strike me as a necessarily simple question. Multivariate normal distributions have very special properties, and it's not guaranteed that there's any easy way to generate a spatial random field with the desired correlation structure *and* a marginal truncated lognormal distribution (although even exponentiating, i.e. generating the lognormal from the normal, modifies the variance-covariance structure) – Ben Bolker Nov 06 '12 at 18:54
  • as @BenBolker said, I need to generate a spatial random filed with desired correlation structure, like the correlation length or range, variogram model. I do know how to generate samples from a truncated distribution, but I do not know how to generate a spatially correlated truncated field. – Zhenglei Nov 06 '12 at 20:30

0 Answers0