Dear R experts:
I have following problem:
# myfunction
mfun1 <- function(x) {
if ( x == 2){
xv <- sample(c(2,1,0),100, replace = T, prob = c(0.6, 0.2, 0.2))
}
if ( x == 1){
xv <- sample(c(1,0),100, replace = T, prob = c(0.6, 0.4))
}
if ( x == 0) {
xv <- sample(c(0,0),100, replace = T, prob = c(0.5, 0.5))
}
return(xv)
}
# applying the function
x = mfun1(1)
# just what I know so far, correlated sample for a quantative data (i do not
want !)
library(ecodist)
y <- corgen(x=x, r=.5)$y
What I want is to generate new variable that is correlated at the same new
variable should be a qualitative one with just value 2,1,0 (no decimals).
I have vector of length 100, just an example
vc <- sample(c(2,1,0),100, replace = T, prob = c(0.6, 0.2, 0.2))
I want to apply the above function to this vector, while holding the
correlation for correspondind variables - i.e. X1 and X2 has correlation of
0.5, X2 and X3 has also correlation of 0.5 and X3 and X4 has correlation of
0.5 and so on.
I have already spend considerable time on it, that is how I got to the
group, sorry for that.
--
Ram H
[[alternative HTML version deleted]]