On Thu, 2007-11-08 at 10:19 +0200, sigalit mangut-leiba
wrote:> hello,
> I have a problem in how to generate data in a simulation study.
> I have a logistic model to evaluate p by 3 covariates.
> I need to generate 4 variables: the binary outcome Y and 3 covariates:
> gender (binary) and aps and tiss (continuous variables).
> I have the logistic model which is the expected model:
> log(p(y=1)/(1-p(y=1))=-1.659-0.05*sex+0.063*aps+0.04*tiss0)
>
> I generate the outcome y like this:
>
> for (i in 1:500){
>
> z1[i] <- rbinom(1, 1, .6)
>
> x1[i] <- rbinom(1, 1, .95)
>
> y1[i] <- z1[i]*x1[i]
>
> }
>
> my question is : how to generate the covariates aps, which can get values
> between 2-37, and tiss, which can get values between 9-36.
>
> I want at the and to get similar results as the expected model.
>
> Thank you,
>
> Sigalit.
Hi,
If aps and tiss haven't any kind of distribution is very simple.
aps<-runif(500,2,37) #uniform with 2 and 37
tiss<-runif(500,9,36)
sex<-rbinom(500,1,.51) #binomial with p(sucess)=.51
# now your calculation if a error ~n(0,1.2^2)
logit<--1.659-0.05*sex+0.063*aps+0.04*tiss+rnorm(500,mean=0,sd=1.2)
# converter logit to probability
p<-exp(logit)/(1+exp(logit)
--
Bernardo Rangel Tura, M.D,Ph.D
National Institute of Cardiology
Brazil