[R] Correlated variables

Jim Lemon drjimlemon at gmail.com
Wed Mar 15 22:45:39 CET 2017


Hi Ariel,
It all depends upon n:

n<-2
x1=rnorm(n,0,1);
x2=rnorm(n,0,1);
x3=rnorm(n,0,1);
if(x1+x2-x3>0.25){
  t=rbinom(1, 1, prob=0.25)
}else{
  t=rbinom(1, 1, prob=0.5)
}
n<-1
x1=rnorm(n,0,1);
x2=rnorm(n,0,1);
x3=rnorm(n,0,1);
if(x1+x2-x3>0.25){
  t=rbinom(1, 1, prob=0.25)
}else{
  t=rbinom(1, 1, prob=0.5)
}

Jim


On Thu, Mar 16, 2017 at 1:56 AM, Art U <art.tem.us at gmail.com> wrote:
> Hi,
>
> I'm trying to create binary variable which distribution conditioned on
> other variables. That is what I did,
>
> x1=rnorm(n,0,1);
> x2=rnorm(n,0,1);
> x3=rnorm(n,0,1);
> if(x1+x2-x3>0.25){
>   t=rbinom(1, 1, prob=0.25)
> }else{
>   t=rbinom(1, 1, prob=0.5)
> }
>
> But I always get this the warning:
>
> Warning message:In if (x1 + x2 - x3 > 0.5) { :
>   the condition has length > 1 and only the first element will be used
>
>
> Can I do this without using function "for"?
>
> Thank you in advance.
> Ariel
> --
> *I like to pretend I'm alone*. *Completely alone*. *Maybe post-apocalypse
> or plague*... *Whatever*. *No-one left to act normal for. No need to hide
> who I really am. It would be... freeing*. *...*
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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