outer() or some other function for regression prediction with 2 IVs
On Jul 10, 2012, at 05:35 , Joseph Clark wrote:
Thanks. I was able to get what I wanted by doing this:
predxn <- function(s,d) { coef(m3)[1] + coef(m3)[2]*s + coef(m3)[3]*s^2 + coef(m3)[4]*d + coef(m3)[5]*d^2 }
But it's not very elegant...
You didn't take Michael's hint: coef(m3) %*% cbind(1, s, s^2, d, d^2) or even predict(m3, newdata=data.frame(x1=s, x2=d)) (in which x1, x2 needs replacement to match the names used in m3). Also, a quick (but not fast) solution to the generic non-vectorized-function problem is to Vectorize() it.
// joseph w. clark , phd candidate \\ usc marshall school of business
______________________________________________ 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.
Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com