# [R] help

Michael Dewey lists at dewey.myzen.co.uk
Fri Sep 18 13:25:35 CEST 2015

```Comment in-line

On 18/09/2015 11:04, thanoon younis wrote:
> Hi,
>
>
> I need you help to correct the code below please
> I have this error
> Error in if (v[j] >= 0) yo[i, j] <- 1 else yo[i, j] <- 0 :
>    missing value where TRUE/FALSE needed
>
>
>
>
>
> N<-200;P<-9
> W=matrix(NA, nrow=N, ncol=2)
> xi=matrix(NA, nrow=N, ncol=2)
> Eta=numeric(N)
> phi<-matrix(data=c(1.0,0.3,0.3,1.0),ncol=2)
> yo<-matrix(data=NA,nrow=N1,ncol=P); p<-numeric(P); v<- numeric(P)

When I try your code it fails here because it does not know what N1 is.
Please post code which is self-contained.

> for (t in 1:25) {
>    for (i in 1:N) {
>      xi1[i,]=rmvnorm(1, c(0,0), phi)
>      delta1<-rnorm(1,0,sqrt(0.3))
> eps<-rnorm(3,0,1)
>
> Eta[i]=0.6*W[i,1]+0.6*W[i,1]*xi[i,1]+0.6*W[i,2]*xi[i,2]+0.6*W[i,2]*xi[i,2]*xi[i,2]+0.6*xi[i,1]+0.6*xi[i,2]+0.6*xi[i,1]*xi[i,1]+delta
>      v[1]<-1.0+xi[i,1]; v1[2]<-1.0+0.8*xi1[i,1]; v1[3]<- 1.0+0.8*xi1[i,1]
>      v[4]<-1.0+xi[i,2]; v1[5]<-1.0+0.8*xi1[i,2]; v1[6]<- 1.0+0.8*xi1[i,2]
>      v[7]<-1.0+Eta[i]+eps[1]; v[8]<-1.0+0.8*Eta[i]+eps[2];
>      v[9]<-1.0+0.8*Eta[i]+eps[3]
>
>          for (j in 1:9) { if (v[j]>=0) yo[i,j]<-1 else yo[i,j]<-0 } }
>
> }#end
>
>
>
>
> Any help would be appreciated.
>
>
> Regards
>
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

```