I've solved the condition problem, but have come across another one with the
gcmrec function and was wondering if anyone could point me in the right
direction again? After running the code below, I get this error message:

Error in gcmrec(Survr(id, time, event) ~ var, data = dataOK, s = 1096) :
  NA/NaN/Inf in foreign function call (arg 14)

I've looked into the code of the function and believe it has something to do
with the line "call <- match.call()" but I'm not sure how it works. Thanks
for any input!


# dataset

id=c(rep(1,4),rep(2,4),rep(3,4),rep(4,5))


start=c("1996-01-01","1997-01-01","1998-01-01","1998-03-15","1996-01-01",
"1996-04-15","1997-01-01","1998-01-01","1996-01-01","1997-01-01",
"1998-01-01","1998-09-30","1996-01-01","1997-01-01","1997-12-15",
"1998-01-01","1998-06-14")


stop=c("1997-01-01","1998-01-01","1998-03-15","1999-01-01","1996-04-15",
"1997-01-01","1998-01-01","1999-01-01","1997-01-01","1998-01-01",
"1998-09-30","1999-01-01","1997-01-01","1997-12-15","1998-01-01",
"1998-06-14","1999-01-01")


time=c(366,365,73,292,105,261,365,365,366,365,272,93,366,348,17,164,201)


event=c(0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,1,0)


enum=c(rep(seq(1,4,1),4),5)


var=c(21312,21869,22441,22441,3105,3105,3086,3075,130610,133147,135692,
135692,11686,11976,11976,12251,12251)


data=data.frame(id,start,stop,time,event,enum,var)


# modify Survr function

Survr = function (id, time, event)

{

    if (length(unique(id)) >= length(event[event == 0])) {

        stop("Data doesn't match. Every subject must have a censored time")

    }

    if (length(unique(event)) > 2 | max(event) != 1 | min(event) !=

        0) {

        stop("event must be 0-1")

    }

    ans <- cbind(id, time, event)

    oldClass(ans) <- "Survr"

    invisible(ans)

}


# model

dataOK=addCenTime(data)

m<-gcmrec(Survr(id,time,event)~var, data=dataOK, s=1096)








On Thu, Nov 11, 2010 at 3:50 PM, Emily C <lia.bede...@gmail.com> wrote:

> Sorry for the lack of context - I found a forum (
> http://r.789695.n4.nabble.com/R-help-f789696.html) that I thought was
> easier to navigate and was using it for the first time. Hit the reply
> button, but forgot that the mailing list recipients would not see previous
> message in the thread. I've pasted it at the bottom for reference.
>
> I actually need my data as single year entries as I am assessing the effect
> of a time-varying covariate ("var") that is measured (and changes) on an
> annual basis. However, my events are assessed on a daily basis. But thank
> you for pointing out the condition in Survr(). To correct the problem, I
> believe it would still be valid to change the condition to:
>
> if (length(unique(id)) >= length(event[event == 0])) {
>       stop("Data doesn't match. Every subject must have a censored time")
>
> Thank you for the reply!
>
>
> On Thu, Nov 11, 2010 at 2:54 PM, David Winsemius 
> <dwinsem...@comcast.net>wrote:
>
>>
>> On Nov 11, 2010, at 2:50 PM, David Winsemius wrote:
>>
>>
>>> On Nov 11, 2010, at 2:09 PM, Emily wrote:
>>>
>>>
>>>> I'm having the same problem
>>>>
>>>
>>> (???: from a three year-old posting for which you didn't copy any
>>> context.)
>>>
>>>  and was wondering whether you ever found a
>>>> solution? It gives me the error "Error in Survr(id, time, event) : Data
>>>> doesn't match. Every subject must have a censored time" even though all
>>>> my
>>>> subjects are right-censored, and to be sure, I've even used the
>>>> addCenTime
>>>> function. Any input appreciated!
>>>>
>>>
>>> Your data has a lot of 0 events at the end of calendar years. That does
>>> not
>>>
>>
>>  seem to be the expected format for the Survr records. It appears to
>>> define an
>>>
>>
>>  invalid record as one where the only censoring event is at the time of
>>> the
>>>
>> ^valid^
>>
>>  last observation. Here's the first line in Survr that is throwing the
>>> error:
>>>
>>> if (length(unique(id)) != length(event[event == 0])) {
>>>       stop("Data doesn't match. Every subject must have a censored time")
>>>
>>> I suspect you need to collapse your single-year entries with 0 events
>>> into multiple year entries with an event.
>>>
>>> --
>>> David.
>>>
>>>
>>>> Here's my sample data:
>>>>
>>>> id=c(rep(1,4),rep(2,4),rep(3,4),rep(4,5))
>>>>
>>>>
>>>> start=c("1996-01-01","1997-01-01","1998-01-01","1998-03-15","1996-01-01","1996-04-15","1997-01-01","1998-01-01","1996-01-01","1997-01-01","1998-01-01","1998-09-30","1996-01-01","1997-01-01","1997-12-15","1998-01-01","1998-06-14")
>>>>
>>>>
>>>> stop=c("1997-01-01","1998-01-01","1998-03-15","1999-01-01","1996-04-15","1997-01-01","1998-01-01","1999-01-01","1997-01-01","1998-01-01","1998-09-30","1999-01-01","1997-01-01","1997-12-15","1998-01-01","1998-06-14","1999-01-01")
>>>>
>>>> time=c(366,365,73,292,105,261,365,365,366,365,272,93,366,348,17,164,201)
>>>>
>>>> event=c(0,0,1,0,1,0,0,0,0,0,1,0,0,1,0,1,0)
>>>>
>>>> enum=c(rep(seq(1,4,1),4),5)
>>>>
>>>>
>>>> var=c(21312,21869,22441,22441,3105,3105,3086,3075,130610,133147,135692,135692,11686,11976,11976,12251,12251)
>>>>
>>>> data=data.frame(id,start,stop,time,event,enum,var)
>>>>
>>>> dataOK=addCenTime(data)
>>>> m<-gcmrec(Survr(id,time,event)~var, data=dataOK)
>>>> --
>>>> View this message in context:
>>>> http://r.789695.n4.nabble.com/R-error-using-Survr-function-with-gcmrec-tp858931p3038374.html
>>>> Sent from the R help mailing list archive at Nabble.com.
>>>>
>>>> ______________________________________________
>>>> R-help@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.
>>>>
>>>
>>> David Winsemius, MD
>>> West Hartford, CT
>>>
>>> ______________________________________________
>>> R-help@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.
>>>
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>
> Original message in thread:
>
> Would someone be able to help with this question?  I'm using the
> Gcmrec, Survrec, and Design packages to do a power analysis on
> simulated data.  I'm receiving an error after using the Survr function
> that all data must have a censoring time even after using the gcmrec
> function:  newdata<-addCenTime(olddata).  My program is below.  I'd
> greatly appreciate any help!
>
> id<-c(seq(1,288,by=1),seq(1,79,by=1),seq(1,11,by=1))
> x<-c(rep(0,5),rep(1,6),rep(0,45),rep(1,23),rep(0,124),rep(1,85),
>   +rep(0,4),rep(1,1),rep(0,1),rep(1,5),rep(0,31),rep(1,14),rep(0,5),
>   +rep(1,18),rep(0,8),rep(1,3))
> myrates<-((1-x)*0.0639 + (x)*0.0320)
> y<-c(rexp(378,rate=myrates))
> cen<-c(rexp(378,0.0385))
> time<-pmin(y,cen)
> event<-as.numeric(y<=cen)
> x2<-(x-1)*(-1)
> bvdata<-data.frame(id,event,time,x2)
> bvdata2<-addCenTime(bvdata)
> fit<-cph(Survr(id,event,time)~x2,data=bvdata2)
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to