From: Donald Braman <dbraman_at_law.gwu.edu>

Date: Sun, 22 Jun 2008 18:26:33 -0400

dev.off()

}

}

}

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. Received on Sun 22 Jun 2008 - 22:33:23 GMT

Date: Sun, 22 Jun 2008 18:26:33 -0400

# I've tried to make this easy to paste into R, though it's probably

so simple you won't need to.

# I have some data (there are many more variables, but this is a

reasonable approximation of it)

# I have some are DVs:

dvs <- c("dv1", "dv2", "dv3")

# some IVs:

ivs <- c("iv1", "iv2", "iv3", "iv4", "iv5")

ylab=names(my.df[dv]), col=colors, pch=".") curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col="black") curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col="gray")})

dev.off()

}

}

}

# Question1: Works fine, but using the vector numbers feels kludgy --

especially if the variables in question aren't consecutive.

# Is there a more elegant way of doing this with my lists of variable

names? Something like this, for example:
for(dv in dvs) {

for(iv in ivs) {

for (intv in intvs) {

jpeg(paste(dv, iv, intv, ".jpg", sep="_"))
with(data.frame(my.df), {

my.fit <- lm(my.df[dv] ~ my.df[iv] + my.df[intv] + my.df[iv]:my.df[intv])
colors <- ifelse (my.df[[intv]] == 1, "black", "grey")
plot(my.df[iv], my.df[dv], xlab=iv, ylab=names(dv), col=colors, pch=".")
curve (cbind (1, 1, x, 1*x) %*% coef(my.fit), add=TRUE, col="black")
curve (cbind (1, 0, x, 0*x) %*% coef(my.fit), add=TRUE, col="gray")
})

dev.off()

}

}

}

# Clearly that's wrong -- why it's wrong is obscure to me, though!

Please educate me!

# Question2: Could this could be done by using "apply" rather than a loop?

# Or is looping better here bc there are several actions performed at

each iteration?

# I'm still trying to get my head around all the ways to ditch looping in R.

Donald Braman

http://www.law.gwu.edu/Faculty/profile.aspx?id=10123 http://research.yale.edu/culturalcognition http://ssrn.com/author=286206 ______________________________________________R-help_at_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. Received on Sun 22 Jun 2008 - 22:33:23 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 00:31:03 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*