[R] outer() or some other function for regression prediction with 2 IVs

Joseph Clark joeclark77 at hotmail.com
Tue Jul 10 10:23:39 CEST 2012


I saw the hint but didn't know how to implement it, I learn more every day.

Thanks for spelling it out!

 

I knew there had to be a function like "predict"!




// joseph w. clark , phd candidate
\\ usc marshall school of business


----------------------------------------
> Subject: Re: [R] outer() or some other function for regression prediction with 2 IVs
> From: pdalgd at gmail.com
> Date: Tue, 10 Jul 2012 08:46:42 +0200
> CC: michael.weylandt at gmail.com; r-help at r-project.org
> To: joeclark77 at hotmail.com
>
>
> 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
>
>
>
>
>
>
>
> 		 	   		  


More information about the R-help mailing list