Skip to content

graphics: 3D regression plane

2 messages · Federico Bonofiglio, David Winsemius

#
On Jan 12, 2011, at 6:10 AM, Federico Bonofiglio wrote:

            
There are many. There are limitations to using the ?? operator in that  
it only brings up functions that are installed on your machine but  
when I enter:

??"3D"

... on my machine it nominates a variety of functions from these  
packages:

ca
car
emdbook
grDevices
HH
igraph
lattice
locfit
misc3d
plotrix
raster
rgl
rpanel
scatterplot3d
sm
sna
spatstat
spancs
TeachingDemos
vcdExtra

If you installed the sos package you would have search access to all  
of the functions in CRAN packages (and maybe more).

There are also a variety of graphic galleries:

http://research.stowers-institute.org/efg/R/
http://addictedtor.free.fr/graphiques/allgraph.php
http://rgm2.lab.nig.ac.jp/RGM2/images.php?show=all&pageID=1108
Ah, a critic. And a very non-specific one at that.
Because of poor programming and failure to read the manuals.
First suggestion would be to re-read the predict help page:

You are throwing together symbols in a manner not expected by predict.  
The argument to  newdata is invalid because you did not construct your  
newax dataframe correctly, resulting in only 100 predicted points (at  
the original data).
"newax" should have had column names that match the variables in the  
model. This is what you got:
str(newax)
'data.frame':	10000 obs. of  2 variables:
  $ days: num  0 6.45 12.91 19.36 25.82 ...
  $ expl: num  0.499 0.499 0.499 0.499 0.499 ...
  - attr(*, "out.attrs")=List of 2
   ..$ dim     : Named int  100 100
   .. ..- attr(*, "names")= chr  "days" "expl"
   ..$ dimnames:List of 2
   .. ..$ days: chr  "days=  0.000000" "days=  6.454545" "days=  
12.909091" "days= 19.363636" ...
   .. ..$ expl: chr  "expl=0.4985331" "expl=0.5615784"  
"expl=0.6246238" "expl=0.6876691" ...

Generally is is a bad idea to use "<-" inside data.frame(). I'm not  
sure if it's illegal, but it certainly is confusing.  And the predict  
result might have had the correct length had you had used the "newax"  
dataframe, but it needed to be passed to persp as a properly  
dimensioned  matrix:

?persp

At the end of your constructed example try this instead:

  mod<-lm(y~rd*k)
  newax<- expand.grid(
    rd = seq(min(rd), max(rd), length=100),
    k = seq(min(k), max(k), length=100)
    )
fit <- predict(mod,newax)
graph <- persp(x=seq(min(rd), max(rd), length=100),
                y=seq(min(k), max(k), length=100),
                z= matrix(fit, 100, 100),
                expand=0.5, ticktype="detailed", theta=-45)

persp is not a lattice plotting function, so it does its plotting by  
side-effects. It does return a value but it is only a transformation  
matrix and I do not see that you have intentions to use i the "graph"  
object, but who knows.
David Winsemius, MD
West Hartford, CT