asking for help about an error" Error in xy.coords(x, y) : 'x' and 'y' lengths differ "

I am plotting a calibration during the establishment of the proportional hazards model,but there comes an error after running the last line:

Error in xy.coords(x, y) : 'x' and 'y' lengths differ

code is as follows:

#data reading
seer<-read.table("seer.txt",header=T,sep="\t")

seer$age<-factor(seer$age,labels=c("<50","50-59","60-69","70-79",">=80"))
seer$sex<-factor(seer$sex,labels=c("Female","Male"))
seer$race<-factor(seer$race,labels=c("Black","White","Other"))
seer$stage_T<-factor(seer$stage_T,labels=c("T0","T1","T2","T3a","T3b","T3NOS","T4","TX"))
seer$stage_N<-factor(seer$stage_N,labels=c("N0","N1","NX"))
seer$stage_M<-factor(seer$stage_M,labels=c("M0","M1"))
#establishing the cox model
#3-year
cox1 <- cph(Surv(survival_time,status) ~ age + sex + race +  stage_T + stage_N + stage_M,surv=T,x=T, y=T,time.inc = 1*12*3,data=seer) 

cal <- calibrate(cox1, cmethod="KM", method="boot", u=1*12*3, m= 12000, B=100)

#plotting the calibration curve
pdf("calibrate3.pdf",12,8)
par(mar = c(10,5,3,2),cex = 1.0)
plot(cal,lwd=3,lty=2,errbar.col="black",xlim = c(0,1),ylim = c(0,1),xlab ="Nomogram-Predicted Probability of 3-Year Survival",ylab="Actual 3-Year Survival",col="blue")
lines(cal,c('mean.predicted','KM'),type = 'a',lwd = 3,col ="black" ,pch = 16) #error comes after here

I am very looking forward to your reply!Thank you.

Thanks for your kindness,and could you please give me you email so I can send you the seer.txt ?
It seems that new users have no right to upload files.
Best wishes.

sending seer.txt privately by email would seem to exclude other forum users of the opportunity to help you. Alternatives to consider might be, hosting seer.txt on a file sharing platforming and sharing a link. i.e. github.com
Alternatively, following the reprex guide. a combination of head() and dput() use is usually sufficient. Yarnabrinas link is there if you want to read the guide (recommended).

Sorry for this late reply.It's a bit difficult for me,a non-English speaker to create a link between my computer and github.Here is the link to my github account and you can get the file seer.txt there.https://github.com/hbb1518/document/tree/0b7f406c2dd78838edf6c32f2dbdd07510bf8e89
Thank you for your help and I'm looking forward to your reply.

The last working line of code you have gives:

par(mar = c(10,5,3,2),cex = 1.0)
plot(cal,lwd=3,lty=2,errbar.col="black",xlim = c(0,1),ylim = c(0,1),xlab ="Nomogram-Predicted Probability of 3-Year Survival",ylab="Actual 3-Year Survival",col="blue")

its not exactly clear to me what you intended for

lines(cal,c('mean.predicted','KM'),type = 'a',lwd = 3,col ="black" ,pch = 16) #error comes after here

to do,
but this works and plots a dotted black line over the previous blue line

lines(cal[,'mean.predicted'],cal[,'KM'],lty=3,lwd = 2,col ="black" ,pch = 16) 

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.