I don't run into problems doing this: x=rnorm(300) z=rnorm(300) for (i in 1:300){ p[i]<-exp(-0.834+0.002*x[i]+0.023*z[i])/(1+exp(-0.834+0.002*x[i]+0.023 +z[i])); T[i]<-rbinom(1,1,p[i]) }
hth, Ingmar On 23 Nov 2007, at 10:25, sigalit mangut-leiba wrote: > Hello, > I have a loop with probability computed from a logistic model like > this: > for (i in 1:300){ > > p[i]<-exp(-0.834+0.002*x[i]+0.023*z[i])/(1+exp(-0.834+0.002*x[i]+0.023 > +z[i])) > > x and z generated from normal distribution. > I get 300 different probabilities And I want to generate variables > from > bernulli distribution > with P for every observation: > > T[i]<-rbinom(1,1,p[i]) > But i get missing values for T. > What I'm doing wrong? > Thank you, > Sigalit. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > 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. Ingmar Visser Department of Psychology, University of Amsterdam Roetersstraat 15 1018 WB Amsterdam The Netherlands t: +31-20-5256723 [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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.