[R] How to separate a function by 2 probabilities

Ben Bolker bolker at ufl.edu
Thu Sep 17 21:54:22 CEST 2009




Marcio Resende wrote:
> 
> Good Mourning,
> I have a function to generate a matrix as I show part of it;
> 
> g[j,i]<-if (gen[j,i]==0) al1[i,1]+al1[i,1] else ...
> 
> However i would like that this function occurred with a probability P and
> that another function (another formula to generate g matrix) with
> probability P-1
> 
> That´s it, if P is .7, i would like that in 70% of the times (for random i
> and j) the matrix g was generated according to the formula above and in
> 30% of the times with a different formula which i did not write
> 
> 

something along the lines of

if (runif(1)<0.7) {first formula} else {second formula}

you can probably make this much more efficient by appropriate vectorization,
but you didn't show enough of what you're doing to make specific
recommendations

  cheers

-- 
View this message in context: http://www.nabble.com/How-to-separate-a-function-by-2-probabilities-tp25491943p25492242.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list