s-news
[Top] [All Lists]

Debbuging a function

To: s-news@lists.biostat.wustl.edu
Subject: Debbuging a function
From: "paul hughes" <u7n96@hotmail.com>
Date: Wed, 13 Dec 2000 21:43:45 -0000
Dear All,

I am still having a problem with my function:

y1<-function(n,i,s1,s2,s3,s4)
{
a<-c(0,cumsum(rexp(n-1)))
x<-{c(rep(c(sample(1:i)),n/i))
ifelse(x>(i/2),1,ifelse(x<(i/2),0,0))}
s<-matrix(c(a+s1,a+s1+s2,a+s1+s2+s3,a+s1+s2+s3+s4),ncol=4)
}

If i try to call x i don't get a vector of o's and 1's. This is unusual because if I use this function:

x<-function(i,n)
{
x<-c(rep(c(sample(1:i)),n/i))
ifelse(x>(i/2),1,ifelse(x<(i/2),0,0))
}

I get a vector of zeros and ones. I am sure you are all familiar with block randomisation. I want to order s to give a random sample of numbers 1:i and repeat it n/i number of times. I then need s to replace the each element in the vector with 0 if it is greater than i/2 and 1 if not. I am sure that even the function that works is very inefficient and does not use good programming skills, but this is my first ever experience with a computer language. Eventualy i need y1 to generate a linear combination of a,s,x according to the laird and ware model. In order to do this i need a vector of treatment coeffecients, this is proving troublesome, please help.
_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com


<Prev in Thread] Current Thread [Next in Thread>
  • Debbuging a function, paul hughes <=