All,
I was having trouble trying to create a new class of data and pass it on to
splom (in the lattice library). I mentioned this to Martin Morgan after a talk
he gave. Following is not so much a question, but rather an answer from Morgan
that might be useful to others. Here is the edited part of an email
conversation with him:
On Thursday, August 26, 2010 1:36 PM, Martin Morgan wrote:
Fun! I think the problem is
> x = new("censored", lung$time, event=lung$status)
> x[1:5]
[1] 306 455 1010 210 883
which splom does (subsetting) as part of it's parsing of the general case.
So
setMethod("[", "censored",
function(x, i, j, ..., drop=TRUE)
{
initialize(x, x at .Data[i], event=x at event[i])
})
and
> x[1:5]
An object of class "censored"
[1] 306 455 1010 210 883
Slot "event":
[1] 2 2 1 2 2
which I think works. If so, and if your post is still dangling on R-help, then
maybe you could follow up there to help others in the same position?
Martin
-------------
On 8/26/2010 10:13 AM, Gosink, John wrote:
Hi Martin,
I enjoyed the presentation last night. As per the brief discussion afterwards,
I'm having some trouble getting a new class I created to work its way into
splom. The basic idea is that I want to trick out the upper.panel and
lower.panel functions in splom to recognize different flavors (classes) of
'x' and 'y' values and do different behaviors accordingly.
Below is what I posted to the BioConductor mailing list but didn't get any
answer. Perhaps something is obvious to you? Any advice you could give
would be greatly appreciated.
# This is a new class to combine the time and censoring information
# into one column in the data frame that I'll use
setClass("censored",
representation(event = "numeric"),
contains = "numeric")
# This is a simplification of what I'm doing to show that I'm not
retaining
# the 'censored' class into the lower.panel function
panel.lowerTest <- function(x, y, ...) {
print(class(x))
print(x)
print(class(y))
print(y)
cat("\n\n ---------\n\n")
panel.xyplot(x,y,...)
}
# Here is a simple data example
library(survival)
library(lattice)
data(lung)
lung = lung[1:50,c("inst", "time", "status",
"age", "sex")]
lung$sex = as.factor(c("M", "F")[lung$sex])
# Create a 'censored' object and tack it onto my data set
lung$OS = new("censored", lung$time, event=lung$status)
print(lung$OS) # This is what a 'censored' object should look like
# Do the splom. Notice that the lower panel should have reported that
# it was seeing 'censored' data, but it didn't...
splom(lung[, c("sex", "age", "OS")], lower.panel =
panel.lowerTest)
________________
John Gosink, PhD
Senior Scientist, Amgen, Inc.
1201 Amgen Court West
Seattle, WA 98119-3105
(w) 206 265-8217