Using rbinom might be more clear than my sample() solution. May I
speculate without actual testing that:
inv <- 2*rbinom(length(vec),1,0.5) - 1
might be more efficient than a 2-step rbinom / ifelse strategy?
--
David Winsemius
Heritage Labs
On Nov 18, 2008, at 5:21 PM, joris meys wrote:
T
Just for clarification : this is an extension, where you can take the
probability of switching to any possible value. Take into account that
the p-value in the function rbinom is 1-P for the switching of the
sign.
On Tue, Nov 18, 2008 at 11:21 PM, joris meys <[EMAIL PROTECTED]> wrote:
> The funct
The function rbinom might be a solution.
Try following simple program :
vec <- c(-1,1,-1,1,1,-1,-1,1,1)
inv <-rbinom(length(vec),1,0.5)
inv <-ifelse(inv==0,-1,1)
vec2 <- vec*inv #switches sign with p=0.5
In this, inv is a random binomial vector, where the probability for
being 1 is 0.5 in all
It's generally better to have a descriptive subject as you have done
here but not in your prior psoting.
You might think about how you can use this sort of result:
vec <- c(1, -1, -1, 1, 1, -1)
sample(c(-1,1),length(vec),replace=T)
Perhaps:
vec <- vec*sample(c(-1,1),length(vec),replace=T)
?s
To clear up a question regarding my earlier posting regarding random changes in
a vector:
Say you have a vector (1, -1, -1, 1, 1, -1). I want each value in the vector
to have a probability that it will change signs when this vector is
regenerated. For example, probability = 50%. When the vec
5 matches
Mail list logo