[R] a repetition of simulation

Johannes Hüsing johannes at huesing.name
Thu Nov 15 21:25:47 CET 2007


Excuse me, but I think your code deserves some comments. Unfortunately,
the history of postings is in reverse order, so I'll address your
first question first:

> > >>> The simulation looks like this:
> > >>>
> > >>> z <- 0
> > >>> x <- 0
> > >>> y <- 0
> > >>> aps <- 0
> > >>> tiss <- 0
> > >>> for (i in 1:500){
> > >>> z[i] <- rbinom(1, 1, .6)
> > >>> x[i] <- rbinom(1, 1, .95)
> > >>> y[i] <- z[i]*x[i]

If I'm getting this correctly, you don't need z and x later on?
Then 
y <- rbinom(500, 1, .6*.95) 
should do the trick. 


> > >>> if (y[i]==1) aps[i] <- rnorm(1,mean=13.4, sd=7.09) else aps[i] <-
> > >>> rnorm(1,mean=12.67, sd=6.82)
> > >>> if (y[i]==1) tiss[i] <- rnorm(1,mean=20.731,sd=9.751) else  tiss[i] <-
> > >>> rnorm(1,mean=18.531,sd=9.499)

tiss <- ifelse(y, rnorm(500, mean=20.731, sd=9.751), rnorm(500, mean=18.531, sd=9.499))
Likewise for aps.

> > >>> }
> > >>> v <- data.frame(y, aps, tiss)
> > >>> log_v <- glm(y~., family=binomial, data=v)
> > >>> summary(log_v)

Makes me wonder what you need aps and tiss for. Let's assume for a moment that
they are the coefficients. I do not see the necessity to put everything into a 
data frame, so 

log_v <- glm(y ~ aps+tiss, family=binomial)

should be sufficient and 


summary(log_v)$coefficients[,"Pr(>|z|)"]

extracts the p value.

> how can I see all the P.Values (Pr(>|z|)) of the covariates from the 1000
> iterations?
> I tried names(log_v) and couldn'n find it.

Try str(summary(log_v)) and you see the whole structure.

-- 
Johannes Hüsing               There is something fascinating about science. 
                              One gets such wholesale returns of conjecture 
mailto:johannes at huesing.name  from such a trifling investment of fact.                
http://derwisch.wikidot.com         (Mark Twain, "Life on the Mississippi")



More information about the R-help mailing list