Dear Donald,
You're on the right track, but I would suggest the following:
dvnames <- c("risk.scale", "instr.scale",
"affect.scale")
men <- women <- older <- younger <- list()
## Looping and storing the output
for (ii in dvnames) {
## Use as.formulat(paste(...))) to construct a formula on the fly
z.out <- zelig(as.formula(paste(ii, " ~ male + age")),
model = "ls",
data = mi(miin1, miin2, miin3, miin4, miin5))
x.out <- setx(z.out, male = 1)
x.alt <- setx(z.out, male = 0)
men[[i]] <- sim(z.out, x = x.out)
women[[i]] <- sim(z.out, x = x.alt)
x.out <- setx(z.out, age = 25)
x.alt <- setx(z.out, age = 65)
younger[[i]] <- sim(z.out, x = x.out)
older[[i]] <- sim(z.out, x = x.alt)
}
## You should look at the SD and 95% CI in addition to the mean EV
sum.fn <- function(x) c(mean(x$qi$ev), sd(x$qi$ev), quantile(x$qi$ev,
c(0.025, 0.975)))
sapply(men, sum.fn)
sapply(women, sum.fn)
sapply(older, sum.fn)
sapply(younger, sum.fn)
I haven't tested it, but it should work! Good luck.
Yours,
Olivia
On Mon, Apr 6, 2009 at 3:56 PM, Donald Braman <dbraman(a)law.gwu.edu> wrote:
Is there an easy way to loop through a series of
simulations with
different DVs?
e.g., suppose I have a list of DV names and I want to simulate
quantities of interest for the same model run against each DV. Can I
do something like this:
dvnames <- c("risk.scale", "instr.scale",
"affect.scale")
for (dvname in dvnames) {
z.out <- zelig([dvname] ~ male + age,
model = "ls",
data = mi(miin1, miin2, miin3, miin4, miin5))
x.out <- setx(z.out, male = 1)
x.alt <- setx(z.out, male = 0)
men.mean <-mean(sim(z.out, x = x.out)$qi$ev)
women.mean <-mean(sim(z.out, x = x.alt)$qi$ev)
print(dvname, men.mean, women.mean)
x.out <- setx(z.out, age = 25)
x.alt <- setx(z.out, age = 65)
younger.mean <-mean(sim(z.out, x = x.out)$qi$ev)
older.mean <-mean(sim(z.out, x = x.alt)$qi$ev)
print(dvname, younger.mean, older.mean)
}
I've tried, but haven't yet succeeded. Any advice appreciated!
Don
Donald Braman
Associate Professor of Law
The George Washington University Law School
2000 H Street, NW | Washington, DC 20052
tel (202) 994-0572 | fax (202) 994-3377
http://www.law.gwu.edu/Faculty/profile.aspx?id=10123
http://research.yale.edu/culturalcognition
http://ssrn.com/author=286206
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/?info=zelig
Zelig program information:
http://gking.harvard.edu/zelig/
-
Zelig Mailing List, served by Harvard-MIT Data Center
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/?info=zelig
Zelig program information:
http://gking.harvard.edu/zelig/