[R] How can I generate this numbers

roger koenker roger at ysidro.econ.uiuc.edu
Tue Oct 3 01:10:30 CEST 2006


Try:

 > rsimplex <- function(n){
u <- diff(sort(runif(n)))
c(u,1-sum(u))
}

On Oct 2, 2006, at 5:43 PM, Rolf Turner wrote:

> Ricardo Rios wrote:
>
>> Hi Rolf Turner, I have a  statistical model, it model need this
>> numbers for calculate the probability. This numbers must be random.
>>
>> For example I need that
>>> magicfunction(3)
>>> [1] 0.3152460 0.5231614 0.1615926
>>> magicfunction(3)
>>> [1]  0.6147933 0.3122999  0.0729068
>>
>> but the argument of the function is arbitrary , does somebody
>> know if exist this function in R?
>
> 	As far as I know, no such function exists in R, but
> 	it would be totally trivial to write one, if that's
> 	what you really want.
>
> 	However the question you pose makes little sense to me.  If
> 	you really have a ``statisical model'' then there must be
> 	some marginal distribution for each of the probabilities (I
> 	*assume* They are probabilities) going into the sequence
> 	which you wish to sum to 1.
>
> 	You mention no such distribution.
>
> 	To generate such a sequence with an arbitray marginal
> 	distribution is so trivial that it does not bear discussing.
>
> 	If you really can't see how to do this, then you probably
> 	shouldn't be messing about with ``statistical models''.
>
> 	You did not explicitly deny that this is a homework problem.
>
> 	I still suspect that it is.
>
> 				cheers,
>
> 					Rolf Turner
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list