Hello all, I’m trying to add some data points to a wireframe. X an Y axis are independent variables, Z axis is predicted probability. I’d like to add the original data points on which the predicted probabilities are based to the wireframe. I’ve followed some of the previous post on this but get stuck : ## first part yields the wireframe## setwd("C:/Temp") rnp <- read.table("interact.csv",header=T,sep=";") status <-rnp[,1:1] totalfrost <- rnp[,2:2] logtps <- rnp[,3:3] logpd <- rnp[,4:4] logwinterp <- rnp[,5:5] model <- glm(status~totalfrost+logtps+logpd+logwinterp+totalfrost*logtps+totalfrost*logwinterp,binomial) abc <- expand.grid(totalfrost=seq(-1.9,3.6,by=0.25),logtps=seq(-3.3,1.1,by=0.25),logpd=seq(0.95,4.1, by=0.25),logwinterp=seq(1.49,1.78, by=0.25)) abc$status <-as.vector(predict(model,abc,type="response")) ##below is the import of the original data together with their predicted probabilities## punten <- read.table("probs.csv",header=T,sep=";") x <- punten[,1:1] y <- punten[,2:2] z <- punten[,3:3] pts <- data.frame(x=x,y=y,z=z) ##end import original data## wireframe(status~totalfrost*logtps,abc,scales=list(arrows=TRUE),drape=TRUE, screen =list (x=15, y=-50, z=-105), pts = pts, panel.3d.wireframe function(x, y, z, xlim, ylim, zlim, xlim.scaled, ylim.scaled, zlim.scaled, pts, ...) { panel.3dwire(x = x, y = y, z = z, xlim = xlim, ylim = ylim, zlim = zlim, xlim.scaled = xlim.scaled, ylim.scaled = ylim.scaled, zlim.scaled = zlim.scaled, ...) xx <- xlim.scaled[1] + diff(xlim.scaled) * (pts$x - xlim[1]) / diff(xlim) yy <- ylim.scaled[1] + diff(ylim.scaled) * (pts$y - ylim[1]) / diff(ylim) zz <- zlim.scaled[1] + diff(zlim.scaled) * (pts$z - zlim[1]) / diff(zlim) panel.3dscatter(x = xx, y = yy, z = zz, xlim = xlim, ylim = ylim, zlim = zlim, xlim.scaled = xlim.scaled, ylim.scaled = ylim.scaled, zlim.scaled = zlim.scaled, ...) }) This yields me the following errors : Warning messages: 1: In Ops.factor(pts$x, xlim[1]) : - not meaningful for factors 2: In Ops.factor(pts$y, ylim[1]) : - not meaningful for factors 3: In Ops.factor(pts$z, zlim[1]) : - not meaningful for factors Any idea about what is wrong and what to do about it? Thanks! Diederi Diederik Strubbe Evolutionary Ecology Group Department of Biology, University of Antwerp Universiteitsplein 1 B-2610 Antwerp, Belgium http://webhost.ua.ac.be/deco tel : 32 3 820 23 85 [[alternative HTML version deleted]]
On 4/30/08, Strubbe Diederik <diederik.strubbe at ua.ac.be> wrote:> Hello all, > > I'm trying to add some data points to a wireframe. X an Y axis are independent variables, Z axis is predicted probability. I'd like to add the original data points on which the predicted probabilities are based to the wireframe. I've followed some of the previous post on this but get stuck : > > ## first part yields the wireframe## > setwd("C:/Temp") > rnp <- read.table("interact.csv",header=T,sep=";") > status <-rnp[,1:1] > totalfrost <- rnp[,2:2] > logtps <- rnp[,3:3] > logpd <- rnp[,4:4] > logwinterp <- rnp[,5:5] > model <- glm(status~totalfrost+logtps+logpd+logwinterp+totalfrost*logtps+totalfrost*logwinterp,binomial) > abc <- expand.grid(totalfrost=seq(-1.9,3.6,by=0.25),logtps=seq(-3.3,1.1,by=0.25),logpd=seq(0.95,4.1, by=0.25),logwinterp=seq(1.49,1.78, by=0.25)) > abc$status <-as.vector(predict(model,abc,type="response")) > > ##below is the import of the original data together with their predicted probabilities## > punten <- read.table("probs.csv",header=T,sep=";") > x <- punten[,1:1] > y <- punten[,2:2] > z <- punten[,3:3] > > pts <- data.frame(x=x,y=y,z=z) > ##end import original data## > > > wireframe(status~totalfrost*logtps,abc,scales=list(arrows=TRUE),drape=TRUE, screen =list (x=15, y=-50, z=-105), pts = pts, > panel.3d.wireframe > function(x, y, z, > xlim, ylim, zlim, > xlim.scaled, ylim.scaled, zlim.scaled, > pts, > ...) { > panel.3dwire(x = x, y = y, z = z, > xlim = xlim, > ylim = ylim, > zlim = zlim, > xlim.scaled = xlim.scaled, > ylim.scaled = ylim.scaled, > zlim.scaled = zlim.scaled, > ...) > xx <- > xlim.scaled[1] + diff(xlim.scaled) * > (pts$x - xlim[1]) / diff(xlim) > yy <- > ylim.scaled[1] + diff(ylim.scaled) * > (pts$y - ylim[1]) / diff(ylim) > zz <- > zlim.scaled[1] + diff(zlim.scaled) * > (pts$z - zlim[1]) / diff(zlim) > panel.3dscatter(x = xx, > y = yy, > z = zz, > xlim = xlim, > ylim = ylim, > zlim = zlim, > xlim.scaled = xlim.scaled, > ylim.scaled = ylim.scaled, > zlim.scaled = zlim.scaled, > ...) > }) > > This yields me the following errors : > > Warning messages: > 1: In Ops.factor(pts$x, xlim[1]) : - not meaningful for factors > 2: In Ops.factor(pts$y, ylim[1]) : - not meaningful for factors > 3: In Ops.factor(pts$z, zlim[1]) : - not meaningful for factors > > Any idea about what is wrong and what to do about it?Without access to the data, my only guess is that pty$x etc. are factors. Can you show us tthe output of str(pts)? -Deepayan
Dear Deepayan, I am sorry to bother you again, but I have some more questions on the R wireframe : - when plotting an interaction between two variables, originating from a logistic model with several factors : what happens to the other variables (ie the ones not plotted)? Are they set to 0? Or to their mean? - the script to add points to the wireframe works fine now. However, I'd like to add another set of points to the wireframe (with a different symbol). How should I proceed to do this? I tried to add an additional panel.3d.wireframe and panel.3dwire statement, but apparantly I am making some kind of mistake. Many thanks, Diederik Diederik Strubbe Evolutionary Ecology Group Department of Biology, University of Antwerp Universiteitsplein 1 B-2610 Antwerp, Belgium http://webhost.ua.ac.be/deco tel : 32 3 820 23 85 ________________________________ Van: Deepayan Sarkar [mailto:deepayan.sarkar@gmail.com] Verzonden: wo 30-4-2008 20:18 Aan: Strubbe Diederik Onderwerp: Re: [R] wireframe - add data points On 4/30/08, Strubbe Diederik <diederik.strubbe@ua.ac.be> wrote:> > > > Hello, > > The output of str(pts) is : > > 'data.frame': 123 obs. of 3 variables: > $ x: Factor w/ 88 levels "-0,001290574",..: 33 30 19 42 39 32 21 21 13 38 > ... > $ y: Factor w/ 111 levels "-0,076738454",..: 108 103 110 83 90 95 104 104 > 111 70 ... > $ z: Factor w/ 113 levels "0,00432948","0,008508508",..: 1 2 3 4 5 6 7 7 8 > 9 ... > > > The data look like : > status totalfrost logTPS logPD logWinterp > 1 0.00 0.53 1.21 0.08 > 1 -0.04 -0.24 0.13 -0.83 > 0 -0.07 0.99 1.12 -0.66 > 1 0.10 -1.99 -1.58 0.92 > 0 -0.14 -0.88 -0.60 -0.26 > 1 0.16 0.62 0.62 0.08 > 0 -0.17 -1.87 -0.03 -0.44 > 0 -0.17 -1.76 -1.24 0.43 > 1 -0.18 0.86 0.54 -0.47 > 1 -0.18 0.86 0.54 -0.47 > 0 0.21 -1.02 -0.32 0.65 > 0 0.21 -1.78 -1.62 -0.37 > 0 0.21 -2.36 -0.95 -0.02 > 1 0.21 -0.47 0.35 0.21 > 0 0.21 -0.63 -1.28 -0.02 > 0 0.21 -0.58 -0.08 -0.02 > 0 0.21 0.51 0.47 -0.02 > 0 0.21 -1.55 -0.32 0.63 > ..... > > With the points that I'd like to add to the wireframe as : > > totalfrost logtps z > -1,54069 1,292944 0,004329 > -1,4455 1,101941 0,008509 > -1,00393 1,604134 0,00984 > -1,80995 0,59885 0,013043 > -1,68756 0,67048 0,013816 > -1,50534 0,809675 0,01441 > -1,05929 1,150182 0,019563 > -1,05929 1,150182 0,019563 > -0,70524 1,691427 0,020248 > ....... > > > Hope this helps and many thanks!!It should help you: as the message suggests, pts$x etc. are factors (I'm guessing because of the use of commas for the decimal point), whereas you want them to be numeric. In other words, the problem is not in your wireframe code, it's in your data preprocessing. -Deepayan [[alternative HTML version deleted]]