Skip to content
Prev 298952 / 398503 Next

Specify model with polynomial interaction terms up to degree n

On Jul 2, 2012, at 4:13 PM, YTP wrote:

            
No. It _was_ doing what you asked for. I think you don't understand  
the expansion.
Degree 3 and 4 ???  That wasn't how I would have described the results  
(there being only first and second order terms as determined by the  
'degree' argument), but the fact remains.... You cannot estimate more  
than three parameters with a dataset of only 3 points. That is basic  
math.

It seems you have demonstrated that these weapons are "too sharp" to  
be wielded safely in your hands, so maybe you should step back a few  
paces and re-consider what you are really trying to accomplish. Is the  
goal really curve fitting with with N^2 polynomial parameters. And do  
you _really_ want to be describing to your audience the interpretation  
of models created with a logit link that have high degree polynomial  
terms? Or are you instead interested in flexible regression for  
purposes of description or exploratory analyses such as provided by  
loess (one form of local regression) or perhaps GAM's with smoothing  
terms?

test = data.frame(y = rnorm(1000),X1=rnorm(1000), X2=rnorm(1000) )
plot.new()
persp( x= seq(-2, 2,by=0.1),  y= seq(-2, 2,by=0.1),
        z= predict(mymodel2,
           newdata =expand.grid(X1=seq(-2, 2,by=0.1), X2=seq(-2,  
2,by=0.1)) ) ,
        ticktype="detailed")

This has the advantage that the polynomial basis is hidden and you  
only end up looking at the predictions. I also like working with Frank  
Harrell's 'rms' package because his perimeter function restricts  
plotted estimates to regions with sufficient data and the restricted  
cubic splines have less tendency to blow-up near the boundaries of hte  
data.
Orthogonal basis.
?poly

You can get something like that with poly(X1, degree=2, raw=TRUE)

 > poly(1:3, degree=2, raw=TRUE)
      1 2
[1,] 1 1
[2,] 2 4
[3,] 3 9
attr(,"degree")
[1] 1 2
attr(,"class")
[1] "poly"   "matrix"