I've   attached a sample of the data sets, this is my full code.

#R 2.13
#library(survival)
#library(Hmisc)
#library(splines)
library(rms)
train<-as.data.frame( train<-read.csv("G:\\train.txt", header=T, sep="\t"))
test<-as.data.frame( test<-read.table("G:\\test.txt", header=T, sep="\t"))
f.1<-cph(Surv(time,event)~age, x=T, y=T,surv=T, data=train)
val.surv(f.1, newdata=test, u=10)


#plot(calibrate(f.1, u=30, B=20))





________________________________
From: David Winsemius <dwinsem...@comcast.net>
To: Salvo Mac <salvo_...@yahoo.com>
Cc: "r-help@R-project.org" <r-help@r-project.org>
Sent: Sunday, August 21, 2011 5:29 AM
Subject: Re: [R] val.surv


On Aug 20, 2011, at 10:25 PM, Salvo Mac wrote:

> The test and train are like split data sets, contain similar variables but 
> from different countries so the two sets are somehow  independent. And yes it 
> is a data frame.

What is a data.frame? test and train may be dataframes, but test[, "age"] is 
not a dataframe.

> So I extracted age, time and event.

Code? The code you offered before would have created a newdata object (yes, a 
data.frame) with a single column bearing the same name as the vector argument 
,,,,, "test1". Not named "age". Try it. do str on such an object:

str(dataframe(test1))


> So test is data frame,(age, time, event). does that suffice?

It certainly does not allow me to reproduce the error you got (which I still 
think is probably related to the structure of your argument to newdata.)

That's all I can say without data and code.

--David.


> 
> 
> 
> ________________________________
> From: David Winsemius <dwinsem...@comcast.net>
> 
> Cc: "r-help@R-project.org" <r-help@r-project.org>
> Sent: Sunday, August 21, 2011 3:19 AM
> Subject: Re: [R] val.surv
> 
> 
> On Aug 20, 2011, at 8:08 PM, Salvo Mac wrote:
> 
>> Thanks David
>> 
>> However, I tried your trick on val.surv with newdata=test['age'] but still 
>> didn't work.
>> Still gives the same error message:
>> 
>> Error in val.surv(f.1, newdata = test1["age"], u = 10) :
>>    dims [product 1797] do not match the length of object [2496]
>> In addition: Warning message:
>> In est.surv + S[, 1] :
>>    longer object length is not a multiple of shorter object length
>> 
> 
> As I said (and you did
> not act  upon):
> 
> The fundamental thing you are doing wrong for q1  is failing to unambiguously 
> describe the test object.
> 
> I said it was a guess. Now stop wasting our time and offer what is needed.
> 
> --david.
>> 
>> Salvo
>> ________________________________
>> From: David Winsemius <dwinsem...@comcast.net>
>> 
>> Cc: "r-help@R-project.org" <r-help@r-project.org>
>> Sent: Sunday, August 21, 2011 12:55 AM
>> Subject: Re: [R] val.surv
>> 
>> 
>> On Aug 20, 2011, at 3:32 PM, Salvo Mac wrote:
>> 
>>>    Dear R-users,
>>> 
>>> I  have two questions regarding
> validation and calibration of Survival regression models.
>>> 
>>> 1.  I am trying to calibrate and validate a cox model using val.surv.
>>> here is my code:
>>>    f.1<-cph(Surv(time,event)~age, x=T, y=T, data=train)
>>>    test1<-test[,"age"]
>>>    val.surv(f.1, newdata=data.frame(test1), u=10)
>>> 
>>>    but I get an error message:
>>> 
>>>    Error in val.surv(f.1, newdata = data.frame(testi), u = 10) :
>>>     dims [product 1797] do not match the length of object [2496]
>>>    In addition: Warning message:
>>> In est.surv + S[, 1] :
>>>     longer object length is not a multiple of shorter object length
>>> 
>>>    I ran the example in the r-documentation but couldn't extract  dxy from 
>>>result.
>>> 
>>>    What am I doing wrong?
>> 
>> The fundamental thing you are doing wrong for q1  is failing to 
>> unambiguously describe the test object. I would think that if test were a 
>> dataframe then wrapping data.frame around a vector might not get it named 
>> correctly as 'age'. You might try newdata= test['age']. Just a guess.
>> 
>>> 
>>>    2.  In validate and calibrate cph functions. If it is frailty fit, does 
>>>the the bootstrap resample clusters or just individuals
>> 
>> The code above appears to be dependent on the rms package. The frailty 
>> function is part of the underlying survival package and I do not see it 
>> mentioned in the index for Harrell's RMS text. You will probably need to 
>> wait until Frank comes across this. He is generally very good about 
>> correction my errors and knowledge gaps.
>> 
>>> 
>> 

David Winsemius, MD
West Hartford, CT
id      age     weight  gender  time    event
1       32      14      0       183     0
3       56      9       0       12      1
4       42      5       0       183     0
5       79      13      0       4       1
6       30      3       0       183     0
7       19      10      0       183     0
8       18      12      0       3       1
9       26      14      0       183     0
10      24      14      0       1       1
11      35      6       0       183     0
12      78      14      0       2       1
13      22      7       0       183     0
14      48      5       0       183     0
15      49      13      0       183     0
16      61      5       0       183     0
19      82      14      0       6       1
20      22      10      0       183     0
21      32      4       1       183     0
22      38      9       1       6       1
23      37      3       1       183     0
24      30      13      1       183     0
25      83      14      0       183     0
26      42      14      0       9       1
27      24      8       0       183     0
29      24      14      0       183     0
32      21      14      0       183     0
33      34      3       0       183     0
35      87      13      0       183     0
36      27      14      0       8       1
37      34      3       1       183     0
38      86      13      0       183     0
39      20      5       0       9       1
40      66      9       0       183     0
41      89      13      0       183     0
42      79      8       1       183     0
43      40      7       0       2       1
44      35      3       1       183     0
45      31      14      0       183     0
46      33      9       0       183     0
47      38      10      0       4       1
49      23      7       1       183     0
50      28      14      0       183     0
51      22      13      0       183     0
52      28      3       0       5       1
53      71      3       0       183     0
54      20      5       1       183     0
55      42      14      0       8       1
56      44      14      0       183     0
57      22      8       0       183     0
58      32      4       0       183     0
59      74      5       0       1       1
60      63      12      0       183     0
62      34      3       0       183     0
63      60      14      0       3       1
64      21      12      0       183     0
65      48      6       0       183     0
66      34      4       0       1       1
71      26      3       0       183     0
72      48      14      0       183     0
73      32      13      0       183     0
74      16      11      0       183     0
75      16      4       0       183     0
76      36      5       0       183     0
78      56      11      0       183     0
79      22      8       0       183     0
80      81      14      0       9       1
81      32      12      0       183     0
82      30      3       1       183     0
83      34      11      0       183     0
84      81      3       0       1       1
85      39      14      0       183     0
86      21      13      0       183     0
87      70      14      0       183     0
88      20      10      0       183     0
90      36      3       0       183     0
91      21      9       0       183     0
92      76      9       0       13      1
93      55      12      0       183     0
95      41      8       0       183     0
96      40      11      0       183     0
97      23      4       0       183     0
98      38      3       1       183     0
99      35      3       1       183     0
101     40      12      0       183     0
102     30      3       1       183     0
103     16      3       0       183     0
104     18      11      0       183     0
105     65      14      0       183     0
107     24      3       0       183     0
109     51      14      0       183     0
110     31      13      0       183     0
111     58      13      1       7       1
112     40      3       0       183     0
113     22      3       0       183     0
114     20      12      0       183     0
116     27      7       0       183     0
117     27      14      0       183     0
118     19      10      0       8       1
119     20      13      0       183     0
124     38      9       0       183     0
127     24      12      0       183     0
128     35      13      0       6       1
129     32      4       0       183     0
132     86      10      0       183     0
134     39      11      0       6       1
136     45      12      0       183     0
138     20      3       0       183     0
142     71      12      0       6       1
143     39      12      0       183     0
146     42      9       0       183     0
148     63      3       0       183     0
149     53      12      0       183     0
150     24      11      0       6       1
152     30      10      0       183     0
153     43      11      0       183     0
154     59      10      0       183     0
156     50      11      0       183     0
159     19      7       0       183     0
162     20      11      0       183     0
165     48      5       1       3       1
167     32      13      0       183     0
169     30      7       0       183     0
173     31      12      0       183     0
174     29      10      0       183     0
175     72      7       0       6       1
176     19      10      0       183     0
178     30      9       0       183     0
180     26      3       0       183     0
182     26      12      0       1       1
183     22      10      0       183     0
184     36      11      0       183     0
185     32      11      0       183     0
186     59      5       1       183     0
192     64      6       0       21      1
196     22      13      0       183     0
198     45      3       0       183     0
199     45      12      0       183     0
201     18      10      0       8       1
203     77      10      0       183     0
205     29      11      0       183     0
210     22      10      0       183     0
211     58      11      0       183     0
212     72      13      0       183     0
214     47      10      0       183     0
219     32      13      0       183     0
220     34      3       1       4       1
221     22      10      0       183     0
222     35      8       0       183     0
223     42      10      0       183     0
224     25      12      0       7       1
226     16      10      0       183     0
228     24      10      0       183     0
229     62      6       0       183     0
233     39      9       0       183     0
234     22      11      0       183     0
239     17      3       0       183     0
245     25      9       0       183     0
247     23      10      0       2       1
250     35      8       0       183     0
258     76      6       0       183     0
260     25      12      0       6       1
262     26      8       0       183     0
264     35      10      0       183     0
265     48      9       0       183     0
266     50      11      0       183     0
269     63      13      0       183     0
279     31      11      0       183     0
281     49      3       1       1       1
289     63      10      0       183     0
290     22      8       0       183     0
292     23      13      0       183     0
294     21      8       0       1       1
299     60      10      0       183     0
308     66      10      0       183     0
309     40      12      0       4       1
311     81      13      0       183     0
312     22      11      0       183     0
321     23      11      0       2       1
322     32      13      0       183     0
323     38      11      0       183     0
326     21      8       0       183     0
328     25      11      0       183     0
329     86      13      0       2       1
331     26      3       0       183     0
343     59      11      0       183     0
346     56      8       0       183     0
347     43      11      0       3       1
348     43      12      0       183     0
349     16      11      0       183     0
350     39      12      0       2       1
353     18      10      0       183     0
354     54      11      0       183     0
355     54      10      0       32      1
357     45      5       0       183     0
358     77      9       0       183     0
362     50      11      0       183     0
363     52      9       0       183     0
366     33      12      0       183     0
367     47      11      0       183     0
368     41      10      0       183     0
372     65      12      0       7       1
373     36      5       0       183     0
375     44      11      0       183     0
379     27      12      0       183     0
381     40      13      0       183     0
391     46      11      0       183     0
394     55      8       0       12      1
395     47      13      0       183     0
396     29      3       1       183     0
401     71      11      0       183     0
403     21      6       0       183     0
410     41      10      0       183     0
411     52      3       1       11      1
418     23      5       0       183     0
422     60      3       1       183     0
423     20      5       1       183     0
424     23      11      0       183     0
425     25      9       1       183     0
426     52      12      0       183     0
428     48      10      0       183     0
429     43      3       1       183     0
430     32      5       1       183     0
434     29      3       1       183     0
436     35      3       1       2       1
444     47      10      0       183     0
445     25      10      0       183     0
449     24      8       1       183     0
450     57      11      0       183     0
451     19      12      0       183     0
453     48      11      0       183     0
454     26      12      0       1       1
455     22      11      0       183     0
457     19      11      0       183     0
459     51      3       1       183     0
462     54      11      0       12      1
466     30      6       1       183     0
467     58      13      0       183     0
469     23      13      0       183     0
471     64      11      0       183     0
473     29      3       1       2       1
474     24      11      0       183     0
477     25      11      0       183     0
492     52      5       1       183     0
497     21      5       0       32      1
498     22      13      0       183     0
499     40      3       0       183     0
502     37      11      0       183     0
506     40      6       0       183     0
508     23      5       0       12      1
510     21      10      0       183     0
511     32      11      0       183     0
512     43      10      0       183     0
514     66      10      0       183     0
516     50      10      0       23      1
517     30      3       0       183     0
518     58      8       0       183     0
519     46      10      0       183     0
520     52      3       0       183     0
522     55      3       0       1       1
523     80      10      0       183     0
525     21      5       0       183     0
528     48      11      0       183     0
529     49      10      0       43      1
531     51      11      0       183     0
533     18      3       0       183     0
534     32      3       0       183     0
535     56      3       0       12      1
536     75      7       0       183     0
537     59      10      0       183     0
541     45      3       0       183     0
542     26      10      0       183     0
545     21      3       0       183     0
547     20      3       0       4       1
549     49      3       0       183     0
550     62      5       0       183     0
563     21      9       0       183     0
567     18      10      0       183     0
568     84      11      0       183     0
569     31      10      0       183     0
570     25      11      0       183     0
573     55      10      0       6       1
574     19      11      0       183     0
579     68      5       1       183     0
580     71      13      0       183     0
585     42      10      0       2       1
587     24      4       0       183     0
588     53      8       0       183     0
589     41      13      0       183     0
594     36      11      0       183     0
603     77      10      0       4       1
608     39      12      0       183     0
609     72      13      1       183     0
612     22      12      0       183     0
623     58      13      0       183     0
624     35      10      0       183     0
625     26      12      0       183     0
629     53      9       0       183     0
631     16      13      0       1       1
633     71      11      0       183     0
634     18      11      0       183     0
637     36      10      0       183     0
638     62      10      0       183     0
643     56      9       0       183     0
646     21      13      0       183     0
647     58      3       0       2       1
649     24      11      0       183     0
652     19      10      0       183     0
657     54      12      0       183     0
660     84      8       0       6       1
661     43      8       0       183     0
666     57      5       0       183     0
668     20      7       0       183     0
674     28      10      0       3       1
678     52      10      0       183     0
id      age     weight  gender  time    event
1       20      13      0       24      1
2       38      9       0       183     0
3       24      12      0       3       1
4       35      13      0       183     0
5       32      4       0       183     0
6       86      10      0       183     0
7       39      11      0       183     0
8       45      12      0       4       1
9       20      3       0       183     0
10      71      12      0       183     0
11      39      12      0       2       1
12      42      9       0       183     0
13      63      3       0       183     0
14      53      12      0       183     0
15      24      11      0       6       1
16      30      10      0       183     0
17      43      11      0       183     0
18      59      10      0       9       1
19      50      11      0       183     0
20      19      7       0       183     0
21      20      11      0       183     0
22      48      5       1       3       1
23      32      13      0       183     0
24      30      7       0       183     0
25      31      12      0       4       1
26      29      10      0       183     0
27      72      7       0       183     0
28      19      10      0       6       1
29      30      9       0       183     0
30      26      3       0       183     0
31      26      12      0       3       1
32      22      10      0       183     0
33      36      11      0       12      1
34      32      11      0       183     0
35      59      5       1       183     0
36      64      6       0       1       1
37      22      13      0       183     0
38      45      3       0       183     0
39      45      12      0       183     0
40      18      10      0       1       1
41      77      10      0       183     0
42      29      11      0       1       1
43      22      10      0       183     0
44      58      11      0       2       1
45      72      13      0       183     0
46      47      10      0       183     0
47      32      13      0       183     0
48      34      3       1       4       1
49      22      10      0       183     0
50      35      8       0       183     0
51      42      10      0       183     0
52      25      12      0       12      1
53      16      10      0       183     0
54      24      10      0       183     0
55      62      6       0       183     0
56      39      9       0       183     0
57      22      11      0       183     0
58      17      3       0       33      1
59      25      9       0       183     0
60      23      10      0       183     0
61      35      8       0       183     0
62      76      6       0       23      1
63      25      12      0       183     0
64      26      8       0       183     0
65      35      10      0       183     0
66      48      9       0       23      1
67      50      11      0       183     0
68      63      13      0       183     0
69      31      11      0       183     0
70      49      3       1       1       1
71      63      10      0       183     0
72      22      8       0       183     0
73      23      13      0       183     0
74      21      8       0       183     0
75      60      10      0       183     0
76      66      10      0       183     0
77      40      12      0       183     0
78      81      13      0       183     0
79      22      11      0       183     0
80      23      11      0       183     0
81      32      13      0       183     0
82      38      11      0       183     0
83      21      8       0       183     0
84      25      11      0       6       1
85      86      13      0       183     0
86      26      3       0       183     0
87      59      11      0       183     0
88      56      8       0       183     0
89      43      11      0       183     0
90      43      12      0       8       1
91      16      11      0       183     0
92      39      12      0       183     0
93      18      10      0       183     0
94      54      11      0       183     0
95      54      10      0       183     0
96      45      5       0       183     0
97      77      9       0       9       1
98      50      11      0       183     0
99      52      9       0       183     0
100     33      12      0       183     0
101     47      11      0       183     0
102     41      10      0       183     0
103     65      12      0       7       1
104     36      5       0       183     0
105     44      11      0       183     0
106     27      12      0       183     0
107     40      13      0       183     0
108     38      13      0       9       1
109     46      11      0       183     0
110     55      8       0       183     0
111     47      13      0       183     0
112     29      3       1       183     0
113     71      11      0       183     0
114     21      6       0       183     0
115     41      10      0       183     0
116     52      3       1       11      1
117     23      5       0       183     0
118     60      3       1       183     0
119     20      5       1       183     0
120     23      11      0       183     0
121     25      9       1       183     0
122     52      12      0       12      1
123     48      10      0       183     0
124     43      3       1       183     0
125     32      5       1       183     0
126     29      3       1       183     0
127     35      3       1       2       1
128     47      10      0       183     0
129     25      10      0       183     0
130     24      8       1       183     0
131     57      11      0       183     0
132     19      12      0       183     0
133     48      11      0       2       1
134     26      12      0       183     0
135     22      11      0       183     0
136     19      11      0       183     0
137     51      3       1       183     0
138     54      11      0       8       1
139     30      6       1       183     0
140     58      13      0       183     0
141     23      13      0       183     0
142     64      11      0       183     0
143     29      3       1       2       1
144     24      11      0       183     0
145     25      11      0       183     0
146     52      5       1       183     0
147     21      5       0       183     0
148     22      13      0       183     0
149     40      3       0       183     0
150     37      11      0       12      1
151     40      6       0       183     0
152     23      5       0       183     0
153     21      10      0       183     0
154     32      11      0       183     0
155     43      10      0       3       1
156     66      10      0       183     0
157     50      10      0       183     0
158     30      3       0       183     0
159     58      8       0       183     0
160     46      10      0       183     0
161     52      3       0       5       1
162     55      3       0       183     0
163     80      10      0       183     0
164     21      5       0       4       1
165     48      11      0       183     0
166     49      10      0       183     0
167     51      11      0       183     0
168     18      3       0       183     0
169     32      3       0       183     0
170     56      3       0       183     0
171     75      7       0       9       1
172     59      10      0       183     0
173     45      3       0       183     0
174     26      10      0       183     0
175     21      3       0       183     0
176     20      3       0       183     0
177     49      3       0       183     0
178     62      5       0       183     0
179     21      9       0       8       1
180     18      10      0       183     0
181     84      11      0       183     0
182     31      10      0       8       1
183     25      11      0       183     0
184     55      10      0       183     0
185     19      11      0       183     0
186     68      5       1       183     0
187     71      13      0       2       1
188     42      10      0       183     0
189     24      4       0       1       1
190     53      8       0       183     0
191     41      13      0       183     0
192     36      11      0       183     0
193     77      10      0       4       1
194     39      12      0       183     0
195     72      13      1       183     0
196     22      12      0       183     0
197     58      13      0       12      1
198     35      10      0       183     0
199     26      12      0       1       1
200     53      9       0       183     0
201     16      13      0       183     0
202     71      11      0       1       1
203     18      11      0       183     0
204     36      10      0       3       1
205     62      10      0       183     0
206     56      9       0       6       1
207     21      13      0       183     0
208     58      3       0       2       1
209     24      11      0       183     0
210     19      10      0       183     0
______________________________________________
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