[R] Problem with predict.coxph

Michael Conklin michael.conklin at markettools.com
Wed Aug 19 16:21:53 CEST 2009


In examining the predict.coxph functions for the library I have with 2.7.1 versus the library with 2.9.1 I find a major rewrite of the function. A number of "internal survival functions" are no longer present so much of the code has changed.  This makes identifying the specific problem beyond my capabilities.  What I want to do, is generate predictions for specific combinations of covariates. The number of combinations I am interested in is different than the number of records in the original data file. Any help would be appreciated as some of the graphic routines I want to use on the data are only available in 2.8 or greater - meaning I am currently looking at trying to run two different versions of R to get the project done.

TIA,

Michael Conklin 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Michael Conklin
Sent: Tuesday, August 18, 2009 8:26 PM
To: r-help at r-project.org
Subject: [R] Problem with predict.coxph

We occasionally utilize the coxph function in the survival library to fit multinomial logit models. (The breslow method produces the same likelihood function as the multinomial logit). We then utilize the predict function to create summary results for various combinations of covariates.  For example:

mod1<-coxph(Depvar~Price:Product+strata(ID),data=MyDCMData2,na.action=na.omit,method="breslow")

The model runs fine.

Then we create some new data that is all combinations of Price and Product and retrieve the summary linear predictors.

newdata=expand.grid(Price=factor(as.character(1:5)),Product=factor(as.character(1:5)))
## create a utility matrix for all combinations of prices and products
totalut<-predict(mod1,newdata=newdata,type="lp")

Under R 2.7.1 this produces the following output:

> totalut
          [,1]
1   0.01534582
2  -0.07628528
3  -0.88085189
4  -1.19458045
5  -1.03579684
6   0.40065672
7   0.15922492
8  -0.49233524
9  -0.65483441
10 -1.07739920
11  0.27589201
12  0.48055065
13  0.33638585
14 -0.28416678
15 -0.48762319
16  1.06071986
17  0.69041596
18  0.67479476
19  0.36360168
20 -0.09492167
21  0.66554276
22  0.55748465
23  0.37596413
24  0.01612020
25 -0.03567735
>

The problem is that under R 2.8.1 and R 2.9.1 the previous line fails with the following error:

> totalut<-predict(mod1,newdata=newdata,type="lp")
Error in model.frame.default(Terms2, newdata, xlev = object$xlevels) :
  variable lengths differ (found for 'Price')
In addition: Warning message:
'newdata' had 25 rows but variable(s) found have 43350 rows


Does anyone have an idea what is going on?

Best regards,

Michael Conklin



W. Michael Conklin
Chief Methodologist

MarketTools, Inc. | www.markettools.com<http://www.markettools.com>
6465 Wayzata Blvd | Suite 170 |  St. Louis Park, MN 55426.  PHONE: 952.417.4719 | CELL: 612.201.8978
This email and attachment(s) may contain confidential and/or proprietary information and is intended only for the intended addressee(s) or its authorized agent(s). Any disclosure, printing, copying or use of such information is strictly prohibited. If this email and/or attachment(s) were received in error, please immediately notify the sender and delete all copies


	[[alternative HTML version deleted]]

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




More information about the R-help mailing list