Re: [R] How to separate a function by 2 probabilities

2009-09-17 Thread Ben Bolker
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

Re: [R] How to separate a function by 2 probabilities

2009-09-17 Thread Bert Gunter
n...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Marcio Resende Sent: Thursday, September 17, 2009 8:11 AM To: r-help@r-project.org Subject: [R] How to separate a function by 2 probabilities Good Mourning, I have a function to generate a matrix as I show part of it; g[j,i]<

Re: [R] How to separate a function by 2 probabilities

2009-09-17 Thread Schalk Heunis
Marcio Define two functions, e.g. f1<-function(i,j) i+j f2<-function(i,j) i-j then call them based on the probability e.g. 0.7 f <- if(runif(1)>0.7) f1 else f2 f(1,1) or more compact (if(runif(1)>0.7) f1 else f2)(1,1) HTH Schalk Heunis On Thu, Sep 17, 2009 at 5:10 PM, Marcio Resende wrote: > >

[R] How to separate a function by 2 probabilities

2009-09-17 Thread Marcio Resende
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,