Compute fitted values and regression terms for a model fitted by coxph

# S3 method for class 'coxph'
predict(object, newdata,
type=c("lp", "risk", "expected", "terms", "survival"),
se.fit=FALSE, na.action=na.pass, terms=names(object$assign), collapse,
reference=c("strata", "sample", "zero"),  ...)

Arguments

object

the results of a coxph fit.

newdata

Optional new data at which to do predictions. If absent predictions are for the data frame used in the original fit. When coxph has been called with a formula argument created in another context, i.e., coxph has been called within another function and the formula was passed as an argument to that function, there can be problems finding the data set. See the note below.

type

the type of predicted value. Choices are the linear predictor ("lp"), the risk score exp(lp) ("risk"), the expected number of events given the covariates and follow-up time ("expected"), and the terms of the linear predictor ("terms"). The survival probability for a subject is equal to exp(-expected).

se.fit

if TRUE, pointwise standard errors are produced for the predictions.

na.action

applies only when the newdata argument is present, and defines the missing value action for the new data. The default is to include all observations. When there is no newdata, then the behavior of missing is dictated by the na.action option of the original fit.

terms

if type="terms", this argument can be used to specify which terms should be included; the default is all.

collapse

optional vector of subject identifiers. If specified, the output will contain one entry per subject rather than one entry per observation.

reference

reference for centering predictions, see details below

...

For future methods

Value

a vector or matrix of predictions, or a list containing the predictions (element "fit") and their standard errors (element "se.fit") if the se.fit option is TRUE.

Details

The Cox model is a relative risk model; predictions of type "linear predictor", "risk", and "terms" are all relative to the sample from which they came. By default, the reference value for each of these is the mean covariate within strata. The underlying reason is both statistical and practial. First, a Cox model only predicts relative risks between pairs of subjects within the same strata, and hence the addition of a constant to any covariate, either overall or only within a particular stratum, has no effect on the fitted results. Second, downstream calculations depend on the risk score exp(linear predictor), which will fall prey to numeric overflow for a linear predictor greater than .Machine\$double.max.exp. The coxph routines try to approximately center the predictors out of self protection. Using the reference="strata" option is the safest centering, since strata occassionally have different means. When the results of predict are used in further calculations it may be desirable to use a single reference level for all observations. Use of reference="sample" will use object$means, which agrees with the linear.predictors component of the coxph object. Predictions of type="terms" are almost invariably passed forward to further calculation, so for these we default to using the sample as the reference. A reference of "zero" causes no centering to be done.

Predictions of type "expected" or "survival" incorporate the baseline hazard and are thus absolute instead of relative; the reference option has no effect on these. These values depend on the follow-up time for the subjects as well as covariates so the newdata argument needs to include both the right and left hand side variables from the formula. (The status variable will not be used, but is required since the underlying code needs to reconstruct the entire formula.)

Models that contain a frailty term are a special case: due to the technical difficulty, when there is a newdata argument the predictions will always be for a random effect of zero.

For predictions of type expected a user will normally want to use \(\Lambda(t_i)\), i.e., the cumulative hazard at the individual follow-up time \(t_i\)of each individual subject. This is E in the martingale residual O-E and plays a natural role in assessments of model validation (Crowson 2016). For predictions of type survival, on the other hand, a user will normally want S(tau), where tau is a single pre-specified time point which is the same for all subjects, e.g., predicted 5 year survival. The newdata data set should contain actual survival time(s) for each subject for the first case, as the survival time variable(s), and the target time tau in the second case; (0, tau) for (time1, time2) data.

For counting process data with (time1, time2) form, residuals of type expected estimate the increment in hazard over said interval, and those of type survival the probability of an event at time2 given that the observation is still alive at time1. The estimated hazards over two intervals (t1, t2) and (t2, t3) add to the total hazard over the interval (t1, t3), and the variances also add: the formulas treat these as independent increments, given the covariates. Estimated survivals multiply, but variances do not add.

Note

Some predictions can be obtained directly from the coxph object, and for others it is necessary for the routine to have the entirety of the original data set, e.g., for type = terms or if standard errors are requested. This extra information is saved in the coxph object if model=TRUE, if not the original data is reconstructed. If it is known that such residuals will be required overall execution will be slightly faster if the model information is saved.

In some cases the reconstruction can fail. The most common is when coxph has been called inside another function and the formula was passed as one of the arguments to that enclosing function. Another is when the data set has changed between the original call and the time of the prediction call. In each of these the simple solution is to add model=TRUE to the original coxph call.

References

C Crowson, E Atkinson and T Therneau, Assessing calibration of prognostic risk scores, Stat Methods Med Res, 2016.

Examples

options(na.action=na.exclude) # retain NA in predictions
fit <- coxph(Surv(time, status) ~ age + ph.ecog + strata(inst), lung)
#lung data set has status coded as 1/2
mresid <- (lung$status-1) - predict(fit, type='expected') #Martingale resid 
predict(fit,type="lp")
#>            1            2            3            4            5            6 
#>  0.215495605 -0.423532231 -0.559265038  0.183469551 -0.539432878  0.248095483 
#>            7            8            9           10           11           12 
#>  0.406461814  0.489169379 -0.047448917  0.327284344  0.040389888  0.550315552 
#>           13           14           15           16           17           18 
#> -0.115925255           NA  0.055807340  0.110906025  0.050567124  0.493760215 
#>           19           20           21           22           23           24 
#>  0.557645717 -0.004245606 -0.127236322 -0.621260082 -0.319524466 -0.575882288 
#>           25           26           27           28           29           30 
#> -0.345688084  0.202851214 -0.428371074  1.313400384 -0.021210624  0.761244928 
#>           31           32           33           34           35           36 
#>  0.191540147  0.749933860  0.180240469  0.459827013  0.672213041  0.625512121 
#>           37           38           39           40           41           42 
#>  0.565173220  0.085767683  0.761244928  0.076972823  0.330513426  0.511791514 
#>           43           44           45           46           47           48 
#> -0.439682141  0.660901974 -0.164699618  0.496950353 -0.381077937  0.091073865 
#>           49           50           51           52           53           54 
#> -0.354839644 -0.175654221  0.192873470 -0.447487689 -0.450985298 -0.562055013 
#>           55           56           57           58           59           60 
#>  0.063012023 -0.516810744 -0.297203343  0.474684682  0.034518529  0.076972823 
#>           61           62           63           64           65           66 
#>  0.678283893 -0.045992266  0.176731471 -0.149858457  0.158940268  0.718790633 
#>           67           68           69           70           71           72 
#>  0.539004484 -0.308514410 -0.543216443  0.153500561 -0.479261384 -0.078592144 
#>           73           74           75           76           77           78 
#>  0.946919127 -0.073531430 -0.049489875  0.214162281 -0.641232484  0.029078821 
#>           79           80           81           82           83           84 
#> -0.276488357 -0.392389004 -0.439682141  0.001411510 -0.410013004 -0.151289480 
#>           85           86           87           88           89           90 
#> -0.292311495  0.198744830 -0.039921414 -0.530162769 -0.123010230  0.738622793 
#>           91           92           93           94           95           96 
#> -0.743642023  0.050567124  0.285269157  0.108857156 -0.437633273  0.796634781 
#>           97           98           99          100          101          102 
#>  0.158940268  0.214162281 -0.161169524 -0.400910096 -0.562055013  0.176122695 
#>          103          104          105          106          107          108 
#>  0.012722577  0.108256292  0.617817211  0.157606945 -0.189452466  0.110906025 
#>          109          110          111          112          113          114 
#> -0.026867740  0.797968104 -0.411394980 -0.149248522  0.369011703 -0.344354760 
#>          115          116          117          118          119          120 
#>  0.006456686  0.783867062  0.503880355  0.693378524  0.527693417  0.244122624 
#>          121          122          123          124          125          126 
#> -0.464038972  0.449575370  0.158940268  0.500480446 -0.426322206  0.005322855 
#>          127          128          129          130          131          132 
#> -0.368298829  0.134984810  0.652115157 -0.617153698  0.131479291 -0.190511890 
#>          133          134          135          136          137          138 
#> -0.643882217  0.001411510 -0.460255408  0.666972826  0.067118407  0.583884010 
#>          139          140          141          142          143          144 
#> -0.036137850 -0.399002948  0.747892903  0.215495605  0.630552446  0.088283890 
#>          145          146          147          148          149          150 
#> -0.240346995 -0.200763533 -0.558074111 -0.179200822 -0.232577411 -0.524505653 
#>          151          152          153          154          155          156 
#>  0.171077519 -0.633704981 -0.331136545 -0.190511890  0.477441161           NA 
#>          157          158          159          160          161          162 
#> -0.031097524  0.736573925  0.123673743 -0.013515715 -0.585704233 -0.038186718 
#>          163          164          165          166          167          168 
#>  0.466547245  0.108256292 -0.209943887 -0.716429053 -0.206413793 -0.699828778 
#>          169          170          171          172          173          174 
#>  0.085634157 -0.424865554  0.069277914 -0.441093652  0.107445646 -0.874783994 
#>          175          176          177          178          179          180 
#> -0.047448917  0.046655779  0.557645717  0.001411510 -0.047448917 -0.667994646 
#>          181          182          183          184          185          186 
#> -0.513194586 -0.776965291 -0.614629447  0.019390401 -0.583220496 -0.651086900 
#>          187          188          189          190          191          192 
#>  0.859584155 -0.536642904  0.063145548 -0.712882451  0.024398388  0.369338475 
#>          193          194          195          196          197          198 
#> -0.023370131  0.076972823  0.061878192 -0.368310218 -0.003231734  0.074931865 
#>          199          200          201          202          203          204 
#> -0.629921417 -0.037164935  0.063145548  0.084500326 -0.574393166 -0.627131442 
#>          205          206          207          208          209          210 
#> -0.658814293  0.302547317 -0.410314015  0.516017606  0.131487202 -0.302547317 
#>          211          212          213          214          215          216 
#> -0.539432878  0.153500561  0.119700884  0.409991908 -0.149858457 -0.149858457 
#>          217          218          219          220          221          222 
#> -0.156943432  0.781826105  0.477858312 -0.452404719  0.016633922 -0.081992053 
#>          223          224          225          226          227          228 
#>  0.212705630  0.224016697 -0.750726998  0.703662506  0.142189494 -0.085165683 
predict(fit,type="expected")
#>          1          2          3          4          5          6          7 
#> 0.74602570 0.57892506 1.28411487 0.65144995 2.53474317 2.59935704 0.94925558 
#>          8          9         10         11         12         13         14 
#> 1.07812821 0.63137435 0.55866807 0.31809979 1.96068120 2.96879741         NA 
#>         15         16         17         18         19         20         21 
#> 2.14464916 0.39248100 1.01652225 2.53985878 0.23734050 0.15454932 0.41781121 
#>         22         23         24         25         26         27         28 
#> 0.03725873 1.07425239 0.73304358 0.71922541 1.96068538 0.91425760 0.50868712 
#>         29         30         31         32         33         34         35 
#> 1.07651355 0.10727131 1.64348011 0.22335391 1.34246079 0.18355514 0.25427967 
#>         36         37         38         39         40         41         42 
#> 0.57948554 3.87217595 1.42062915 0.50341133 2.84274107 1.90670187 0.39302876 
#>         43         44         45         46         47         48         49 
#> 1.67374788 0.56009982 1.95081502 0.39930277 0.62185372 1.18384892 1.08920268 
#>         50         51         52         53         54         55         56 
#> 1.36922169 2.72429090 0.31557423 0.04821232 0.41960993 3.07164840 0.12000994 
#>         57         58         59         60         61         62         63 
#> 0.07406041 0.17908976 1.74520134 1.10195998 1.47697029 0.54523697 0.51461493 
#>         64         65         66         67         68         69         70 
#> 0.14292300 0.18117365 0.20227027 0.70028855 1.00636733 0.31133532 0.64126839 
#>         71         72         73         74         75         76         77 
#> 0.96177399 0.46743320 0.53451717 0.16345589 0.86294287 1.44797843 1.06953116 
#>         78         79         80         81         82         83         84 
#> 1.19014609 0.03668315 0.33061179 1.90397464 0.08944145 0.20857044 0.28585781 
#>         85         86         87         88         89         90         91 
#> 1.15723874 0.87295638 1.19851949 0.14216346 1.37338069 0.92021616 1.05096221 
#>         92         93         94         95         96         97         98 
#> 0.27465006 0.47403241 0.26750987 1.01622540 0.08901343 0.32456045 0.93961618 
#>         99        100        101        102        103        104        105 
#> 0.85179714 0.14362313 0.89733451 1.74403467 0.70225748 0.15754565 0.36065915 
#>        106        107        108        109        110        111        112 
#> 0.41227011 0.29089093 0.02759911 2.54485283 1.57705739 0.02915789 0.51482474 
#>        113        114        115        116        117        118        119 
#> 1.51254632 0.24392791 1.95773713 0.16855572 0.69132758 2.65613080 1.04014324 
#>        120        121        122        123        124        125        126 
#> 0.89157179 0.40187641 0.23829273 1.56065440 0.17535194 1.02778525 0.18442460 
#>        127        128        129        130        131        132        133 
#> 0.08051722 0.20596405 1.70473379 0.86354367 0.72017118 0.27146814 0.48487446 
#>        134        135        136        137        138        139        140 
#> 1.10114414 0.51567846 1.46035831 0.93950468 1.54314328 1.12143879 0.60372302 
#>        141        142        143        144        145        146        147 
#> 1.46022571 0.88081136 0.66047105 0.18347489 0.51981101 0.28761918 0.50825077 
#>        148        149        150        151        152        153        154 
#> 0.15268490 0.06671446 0.32571666 0.39746179 0.39772440 0.38939509 0.20940447 
#>        155        156        157        158        159        160        161 
#> 0.62171971         NA 0.34080256 0.46159657 0.47539058 1.00662370 0.21472196 
#>        162        163        164        165        166        167        168 
#> 0.54619593 0.50111574 0.24481910 0.51248548 0.19954882 0.25566706 0.78817717 
#>        169        170        171        172        173        174        175 
#> 0.44798249 0.43113659 0.44847984 1.48341994 0.46620310 0.37028208 0.86812344 
#>        176        177        178        179        180        181        182 
#> 0.43844817 0.94494334 0.25935783 0.37625255 0.20649507 0.25048304 0.37569346 
#>        183        184        185        186        187        188        189 
#> 0.40334526 0.39324727 0.36799524 0.39552828 1.77501387 0.24422514 0.38021709 
#>        190        191        192        193        194        195        196 
#> 0.21501843 0.51818689 0.08032921 0.22774986 0.71502728 0.36774267 0.39500663 
#>        197        198        199        200        201        202        203 
#> 0.38445105 0.97727710 0.43520510 0.16869554 0.17219830 0.05878035 0.21716448 
#>        204        205        206        207        208        209        210 
#> 0.18384556 0.18192355 0.64682101 0.35975276 0.70106697 1.03414013 0.35317899 
#>        211        212        213        214        215        216        217 
#> 0.42921059 0.47944086 0.40234009 0.25017393 0.04470913 0.27054309 0.22137404 
#>        218        219        220        221        222        223        224 
#> 1.18698635 0.50681607 0.11190719 0.11327702 0.28954125 0.33611081 0.74776723 
#>        225        226        227        228 
#> 0.12225025 0.00000000 0.35218786 0.10231300 
predict(fit,type="risk",se.fit=TRUE)
#> $fit
#>         1         2         3         4         5         6         7         8 
#> 1.2404765 0.6547301 0.5716290 1.2013784 0.5830788 1.2815823 1.5014958 1.6309609 
#>         9        10        11        12        13        14        15        16 
#> 0.9536592 1.3871959 1.0412167 1.7338000 0.8905418        NA 1.0573939 1.1172899 
#>        17        18        19        20        21        22        23        24 
#> 1.0518675 1.6384656 1.7465558 0.9957634 0.8805256 0.5372670 0.7264944 0.5622086 
#>        25        26        27        28        29        30        31        32 
#> 0.7077332 1.2248902 0.6515696 3.7187976 0.9790127 2.1409399 1.2111135 2.1168600 
#>        33        34        35        36        37        38        39        40 
#> 1.1975053 1.5838000 1.9585669 1.8692030 1.7597526 1.0895532 2.1409399 1.0800127 
#>        41        42        43        44        45        46        47        48 
#> 1.3916825 1.6682773 0.6442412 1.9365383 0.8481484 1.6437009 0.6831246 1.0953499 
#>        49        50        51        52        53        54        55        56 
#> 0.7012859 0.8389080 1.2127293 0.6392321 0.6370002 0.5700364 1.0650396 0.5964197 
#>        57        58        59        60        61        62        63        64 
#> 0.7428929 1.6075072 1.0351212 1.0800127 1.9704933 0.9550493 1.1933106 0.8608298 
#>        65        66        67        68        69        70        71        72 
#> 1.1722679 2.0519501 1.7142994 0.7345374 0.5808769 1.1659084 0.6192406 0.9244169 
#>        73        74        75        76        77        78        79        80 
#> 2.5777557 0.9291069 0.9517148 1.2388237 0.5266429 1.0295057 0.7584424 0.6754413 
#>        81        82        83        84        85        86        87        88 
#> 0.6442412 1.0014125 0.6636416 0.8595988 0.7465360 1.2198707 0.9608649 0.5885092 
#>        89        90        91        92        93        94        95        96 
#> 0.8842546 2.0930510 0.4753794 1.0518675 1.3301200 1.1150031 0.6455625 2.2180641 
#>        97        98        99       100       101       102       103       104 
#> 1.1722679 1.2388237 0.8511478 0.6697103 0.5700364 1.1925844 1.0128039 1.1143333 
#>       105       106       107       108       109       110       111       112 
#> 1.8548748 1.1707060 0.8274120 1.1172899 0.9734900 2.2210235 0.6627251 0.8613550 
#>       113       114       115       116       117       118       119       120 
#> 1.4463045 0.7086775 1.0064776 2.1899245 1.6551313 2.0004627 1.6950181 1.2765009 
#>       121       122       123       124       125       126       127       128 
#> 0.6287391 1.5676464 1.1722679 1.6495136 0.6529059 1.0053370 0.6919104 1.1445194 
#>       129       130       131       132       133       134       135       136 
#> 1.9195968 0.5394778 1.1405143 0.8265359 0.5252493 1.0014125 0.6311224 1.9483304 
#>       137       138       139       140       141       142       143       144 
#> 1.0694221 1.7929889 0.9645073 0.6709887 2.1125440 1.2404765 1.8786481 1.0922982 
#>       145       146       147       148       149       150       151       152 
#> 0.7863550 0.8181059 0.5723102 0.8359380 0.7924884 0.5918479 1.1865827 0.5306222 
#>       153       154       155       156       157       158       159       160 
#> 0.7181071 0.8265359 1.6119444        NA 0.9693810 2.0887670 1.1316466 0.9865752 
#>       161       162       163       164       165       166       167       168 
#> 0.5567137 0.9625332 1.5944793 1.1143333 0.8106297 0.4884935 0.8134964 0.4966703 
#>       169       170       171       172       173       174       175       176 
#> 1.0894077 0.6538577 1.0717340 0.6433325 1.1134303 0.4169521 0.9536592 1.0477613 
#>       177       178       179       180       181       182       183       184 
#> 1.7465558 1.0014125 0.9536592 0.5127358 0.5985803 0.4597993 0.5408413 1.0195796 
#>       185       186       187       188       189       190       191       192 
#> 0.5580981 0.5214787 2.3621782 0.5847079 1.0651819 0.4902291 1.0246985 1.4467772 
#>       193       194       195       196       197       198       199       200 
#> 0.9769008 1.0800127 1.0638328 0.6919025 0.9967735 1.0778107 0.5326337 0.9635172 
#>       201       202       203       204       205       206       207       208 
#> 1.0651819 1.0881732 0.5630464 0.5341218 0.5174645 1.3533017 0.6634419 1.6753425 
#>       209       210       211       212       213       214       215       216 
#> 1.1405233 0.7389335 0.5830788 1.1659084 1.1271597 1.5068056 0.8608298 0.8608298 
#>       217       218       219       220       221       222       223       224 
#> 0.8547524 2.1854595 1.6126170 0.6360967 1.0167730 0.9212793 1.2370205 1.2510919 
#>       225       226       227       228 
#> 0.4720233 2.0211416 1.1527951 0.9183601 
#> 
#> $se.fit
#>           1           2           3           4           5           6 
#> 0.094027169 0.096340319 0.096185061 0.110144705 0.091221886 0.124003567 
#>           7           8           9          10          11          12 
#> 0.106470052 0.135893441 0.104263809 0.115204660 0.048057506 0.157626321 
#>          13          14          15          16          17          18 
#> 0.058398830          NA 0.078593550 0.044525715 0.047523899 0.139753275 
#>          19          20          21          22          23          24 
#> 0.246130195 0.051683778 0.050651208 0.106747848 0.121191090 0.095563151 
#>          25          26          27          28          29          30 
#> 0.135232494 0.077970827 0.084316589 0.541641696 0.047411370 0.244541270 
#>          31          32          33          34          35          36 
#> 0.067316853 0.236761412 0.222247496 0.143779967 0.246770836 0.214866749 
#>          37          38          39          40          41          42 
#> 0.186808694 0.027994134 0.244541270 0.017746688 0.094899948 0.150429986 
#>          43          44          45          46          47          48 
#> 0.082038635 0.251128992 0.071539989 0.172653479 0.157627962 0.046664065 
#>          49          50          51          52          53          54 
#> 0.203630081 0.147427688 0.071868116 0.087051165 0.126710133 0.091078334 
#>          55          56          57          58          59          60 
#> 0.030346404 0.094111921 0.072518580 0.232795318 0.092391388 0.017746688 
#>          61          62          63          64          65          66 
#> 0.207337260 0.162712161 0.126511646 0.038549743 0.042876315 0.234595146 
#>          67          68          69          70          71          72 
#> 0.151669341 0.068462840 0.112880428 0.068678027 0.124246473 0.184637680 
#>          73          74          75          76          77          78 
#> 0.325442016 0.174862073 0.090441588 0.089040153 0.108376599 0.057550307 
#>          79          80          81          82          83          84 
#> 0.188633743 0.150191651 0.082038635 0.027564795 0.181878087 0.172125872 
#>          85          86          87          88          89          90 
#> 0.142365056 0.114741553 0.035859182 0.096819023 0.132484179 0.229864932 
#>          91          92          93          94          95          96 
#> 0.120689668 0.047523899 0.070339929 0.055381362 0.123547581 0.253870138 
#>          97          98          99         100         101         102 
#> 0.042876315 0.089040153 0.035190905 0.106227011 0.091078334 0.091298269 
#>         103         104         105         106         107         108 
#> 0.017787711 0.028641480 0.194430169 0.039989624 0.075782969 0.044525715 
#>         109         110         111         112         113         114 
#> 0.071209628 0.254965259 0.163546509 0.185211877 0.241649528 0.139074790 
#>         115         116         117         118         119         120 
#> 0.076796420 0.262556790 0.348185429 0.211911041 0.146845572 0.149423594 
#>         121         122         123         124         125         126 
#> 0.150969692 0.156065943 0.042876315 0.142648758 0.129688202 0.004890619 
#>         127         128         129         130         131         132 
#> 0.113985419 0.031310085 0.248637733 0.121183075 0.041502912 0.067248608 
#>         133         134         135         136         137         138 
#> 0.115359144 0.027564795 0.112511267 0.200585657 0.069255092 0.201817172 
#>         139         140         141         142         143         144 
#> 0.094786456 0.075667327 0.240338975 0.094027169 0.216098624 0.024974398 
#>         145         146         147         148         149         150 
#> 0.066191299 0.084423319 0.167625233 0.058808327 0.221289168 0.105873833 
#>         151         152         153         154         155         156 
#> 0.140449741 0.098993713 0.063583542 0.067248608 0.230942129          NA 
#>         157         158         159         160         161         162 
#> 0.067558237 0.245408761 0.032338223 0.075589234 0.101745759 0.174851413 
#>         163         164         165         166         167         168 
#> 0.125897325 0.028641480 0.048065722 0.111659253 0.045260623 0.125085448 
#>         169         170         171         172         173         174 
#> 0.020095538 0.093808006 0.037378627 0.093118562 0.031761359 0.135544076 
#>         175         176         177         178         179         180 
#> 0.104263809 0.016586035 0.246130195 0.027564795 0.104263809 0.174088607 
#>         181         182         183         184         185         186 
#> 0.109727836 0.166211707 0.139230772 0.017941579 0.106388490 0.137198131 
#>         187         188         189         190         191         192 
#> 0.304795981 0.089505183 0.043311645 0.114439474 0.131445121 0.192173147 
#>         193         194         195         196         197         198 
#> 0.144436340 0.017746688 0.058484070 0.121193159 0.002956631 0.025613128 
#>         199         200         201         202         203         204 
#> 0.104623286 0.033429233 0.043311645 0.080773833 0.103942128 0.124008736 
#>         205         206         207         208         209         210 
#> 0.118294076 0.078206752 0.080505144 0.235804861 0.079727031 0.057789591 
#>         211         212         213         214         215         216 
#> 0.091221886 0.068678027 0.029421496 0.124248857 0.038549743 0.038549743 
#>         217         218         219         220         221         222 
#> 0.158976598 0.269332667 0.130275218 0.089792820 0.015369862 0.085131550 
#>         223         224         225         226         227         228 
#> 0.148494109 0.160862263 0.138362860 0.225740927 0.057778343 0.074788433 
#> 
predict(fit,type="terms",se.fit=TRUE)
#> $fit
#>              age     ph.ecog
#> 1    0.130878057  0.03032716
#> 2    0.063011653 -0.54083428
#> 3   -0.072721154 -0.54083428
#> 4   -0.061410086  0.03032716
#> 5   -0.027476885 -0.54083428
#> 6    0.130878057  0.03032716
#> 7    0.063011653  0.60148859
#> 8    0.096944855  0.60148859
#> 9   -0.106654355  0.03032716
#> 10  -0.016165817  0.60148859
#> 11  -0.061410086  0.03032716
#> 12   0.063011653  0.60148859
#> 13   0.063011653  0.03032716
#> 14            NA          NA
#> 15  -0.061410086  0.03032716
#> 16   0.051700586  0.03032716
#> 17   0.085633788  0.03032716
#> 18   0.006456317  0.60148859
#> 19  -0.072721154  0.60148859
#> 20  -0.061410086  0.03032716
#> 21   0.051700586  0.03032716
#> 22  -0.151898625 -0.54083428
#> 23  -0.140587557  0.03032716
#> 24  -0.050099019 -0.54083428
#> 25   0.108255923 -0.54083428
#> 26   0.085633788  0.03032716
#> 27  -0.027476885 -0.54083428
#> 28   0.085633788  1.17265002
#> 29  -0.106654355  0.03032716
#> 30   0.130878057  0.60148859
#> 31   0.074322721  0.03032716
#> 32   0.119566990  0.60148859
#> 33  -0.163209692  0.60148859
#> 34  -0.027476885  0.60148859
#> 35  -0.016165817  0.60148859
#> 36  -0.004854750  0.60148859
#> 37   0.029078452  0.60148859
#> 38   0.040389519  0.03032716
#> 39   0.130878057  0.60148859
#> 40   0.017767384  0.03032716
#> 41   0.085633788  0.03032716
#> 42   0.119566990  0.60148859
#> 43  -0.038787952 -0.54083428
#> 44  -0.027476885  0.60148859
#> 45   0.063011653  0.03032716
#> 46   0.153500192  0.60148859
#> 47   0.130878057 -0.54083428
#> 48   0.006456317  0.03032716
#> 49   0.130878057 -0.54083428
#> 50  -0.140587557  0.03032716
#> 51   0.108255923  0.03032716
#> 52   0.006456317 -0.54083428
#> 53   0.063011653 -0.54083428
#> 54  -0.050099019 -0.54083428
#> 55  -0.038787952  0.03032716
#> 56  -0.004854750 -0.54083428
#> 57   0.029078452 -0.54083428
#> 58  -0.061410086  0.60148859
#> 59  -0.050099019  0.03032716
#> 60   0.017767384  0.03032716
#> 61   0.142189124  0.60148859
#> 62  -0.163209692  0.03032716
#> 63   0.119566990  0.03032716
#> 64   0.029078452  0.03032716
#> 65   0.074322721  0.03032716
#> 66   0.063011653  0.60148859
#> 67   0.051700586  0.60148859
#> 68   0.017767384 -0.54083428
#> 69   0.063011653 -0.54083428
#> 70   0.051700586  0.03032716
#> 71   0.006456317 -0.54083428
#> 72  -0.163209692  0.03032716
#> 73   0.130878057  0.60148859
#> 74  -0.253698230  0.03032716
#> 75  -0.106654355  0.03032716
#> 76   0.096944855  0.03032716
#> 77  -0.129276490 -0.54083428
#> 78  -0.072721154  0.03032716
#> 79   0.210055528 -0.54083428
#> 80   0.119566990 -0.54083428
#> 81  -0.038787952 -0.54083428
#> 82  -0.084032221  0.03032716
#> 83  -0.231076095  0.03032716
#> 84  -0.208453961  0.03032716
#> 85  -0.208453961  0.03032716
#> 86   0.096944855  0.03032716
#> 87  -0.004854750  0.03032716
#> 88  -0.016165817 -0.54083428
#> 89  -0.208453961  0.03032716
#> 90   0.108255923  0.60148859
#> 91   0.006456317 -0.54083428
#> 92   0.085633788  0.03032716
#> 93   0.040389519  0.03032716
#> 94  -0.061410086  0.03032716
#> 95   0.074322721 -0.54083428
#> 96   0.108255923  0.60148859
#> 97   0.074322721  0.03032716
#> 98   0.096944855  0.03032716
#> 99   0.017767384  0.03032716
#> 100  0.085633788 -0.54083428
#> 101 -0.050099019 -0.54083428
#> 102  0.074322721  0.03032716
#> 103 -0.072721154  0.03032716
#> 104  0.006456317  0.03032716
#> 105 -0.038787952  0.60148859
#> 106  0.040389519  0.03032716
#> 107 -0.095343288  0.03032716
#> 108  0.051700586  0.03032716
#> 109 -0.084032221  0.03032716
#> 110  0.142189124  0.60148859
#> 111  0.074322721 -0.54083428
#> 112 -0.208453961  0.03032716
#> 113  0.198744461  0.03032716
#> 114  0.142189124 -0.54083428
#> 115 -0.095343288  0.03032716
#> 116  0.153500192  0.60148859
#> 117 -0.151898625  0.60148859
#> 118  0.063011653  0.60148859
#> 119  0.040389519  0.60148859
#> 120  0.198744461  0.03032716
#> 121  0.142189124 -0.54083428
#> 122 -0.027476885  0.60148859
#> 123  0.074322721  0.03032716
#> 124  0.108255923  0.60148859
#> 125  0.085633788 -0.54083428
#> 126  0.040389519  0.03032716
#> 127 -0.140587557  0.03032716
#> 128  0.017767384  0.03032716
#> 129  0.164811259  0.60148859
#> 130 -0.163209692 -0.54083428
#> 131 -0.038787952  0.03032716
#> 132 -0.106654355  0.03032716
#> 133 -0.174520759 -0.54083428
#> 134 -0.084032221  0.03032716
#> 135  0.051700586 -0.54083428
#> 136  0.130878057  0.60148859
#> 137 -0.050099019  0.03032716
#> 138 -0.072721154  0.60148859
#> 139 -0.095343288  0.03032716
#> 140 -0.072721154 -0.54083428
#> 141  0.119566990  0.60148859
#> 142  0.130878057  0.03032716
#> 143  0.153500192  0.60148859
#> 144  0.029078452  0.03032716
#> 145 -0.061410086  0.03032716
#> 146 -0.106654355  0.03032716
#> 147  0.096944855 -0.54083428
#> 148 -0.095343288  0.03032716
#> 149  0.221366595 -0.54083428
#> 150 -0.038787952 -0.54083428
#> 151  0.085633788  0.03032716
#> 152 -0.027476885 -0.54083428
#> 153 -0.004854750 -0.54083428
#> 154 -0.106654355  0.03032716
#> 155 -0.084032221  0.60148859
#> 156           NA          NA
#> 157  0.063011653  0.03032716
#> 158 -0.004854750  0.60148859
#> 159  0.006456317  0.03032716
#> 160 -0.072721154  0.03032716
#> 161 -0.004854750 -0.54083428
#> 162 -0.208453961  0.03032716
#> 163  0.074322721  0.60148859
#> 164  0.006456317  0.03032716
#> 165  0.017767384  0.03032716
#> 166 -0.061410086 -0.54083428
#> 167 -0.027476885  0.03032716
#> 168 -0.185831826 -0.54083428
#> 169 -0.016165817  0.03032716
#> 170  0.029078452 -0.54083428
#> 171 -0.016165817  0.03032716
#> 172 -0.050099019 -0.54083428
#> 173 -0.072721154  0.03032716
#> 174 -0.219765028 -0.54083428
#> 175 -0.106654355  0.03032716
#> 176 -0.038787952  0.03032716
#> 177 -0.072721154  0.60148859
#> 178 -0.084032221  0.03032716
#> 179 -0.106654355  0.03032716
#> 180  0.130878057 -0.54083428
#> 181 -0.027476885 -0.54083428
#> 182 -0.265009297 -0.54083428
#> 183  0.040389519 -0.54083428
#> 184  0.029078452  0.03032716
#> 185 -0.129276490 -0.54083428
#> 186 -0.197142894 -0.54083428
#> 187  0.108255923  0.60148859
#> 188 -0.050099019 -0.54083428
#> 189  0.017767384  0.03032716
#> 190 -0.106654355 -0.54083428
#> 191  0.108255923  0.03032716
#> 192 -0.117965423  0.60148859
#> 193 -0.140587557  0.03032716
#> 194  0.017767384  0.03032716
#> 195  0.096944855  0.03032716
#> 196  0.085633788 -0.54083428
#> 197  0.006456317  0.03032716
#> 198  0.017767384  0.03032716
#> 199 -0.117965423 -0.54083428
#> 200 -0.027476885  0.03032716
#> 201  0.017767384  0.03032716
#> 202  0.119566990  0.03032716
#> 203  0.006456317 -0.54083428
#> 204 -0.140587557 -0.54083428
#> 205  0.006456317 -0.54083428
#> 206 -0.004854750  0.60148859
#> 207 -0.084032221 -0.54083428
#> 208 -0.140587557  0.60148859
#> 209  0.074322721  0.03032716
#> 210 -0.038787952  0.03032716
#> 211 -0.027476885 -0.54083428
#> 212  0.051700586  0.03032716
#> 213  0.074322721  0.03032716
#> 214  0.017767384  0.60148859
#> 215  0.029078452  0.03032716
#> 216  0.029078452  0.03032716
#> 217 -0.242387163  0.03032716
#> 218  0.153500192  0.60148859
#> 219  0.085633788  0.60148859
#> 220 -0.061410086 -0.54083428
#> 221  0.051700586  0.03032716
#> 222  0.096944855  0.03032716
#> 223  0.153500192  0.03032716
#> 224  0.164811259  0.03032716
#> 225 -0.265009297 -0.54083428
#> 226  0.142189124  0.60148859
#> 227  0.040389519  0.03032716
#> 228 -0.050099019  0.03032716
#> 
#> $se.fit
#>             age     ph.ecog
#> 1   0.119930635 0.007395102
#> 2   0.057740983 0.131879319
#> 3   0.066638322 0.131879319
#> 4   0.056273380 0.007395102
#> 5   0.025178554 0.131879319
#> 6   0.119930635 0.007395102
#> 7   0.057740983 0.146669523
#> 8   0.088835809 0.146669523
#> 9   0.097733148 0.007395102
#> 10  0.014813612 0.146669523
#> 11  0.056273380 0.007395102
#> 12  0.057740983 0.146669523
#> 13  0.057740983 0.007395102
#> 14           NA          NA
#> 15  0.056273380 0.007395102
#> 16  0.047376041 0.007395102
#> 17  0.078470867 0.007395102
#> 18  0.005916272 0.146669523
#> 19  0.066638322 0.146669523
#> 20  0.056273380 0.007395102
#> 21  0.047376041 0.007395102
#> 22  0.139192917 0.131879319
#> 23  0.128827975 0.007395102
#> 24  0.045908438 0.131879319
#> 25  0.099200751 0.131879319
#> 26  0.078470867 0.007395102
#> 27  0.025178554 0.131879319
#> 28  0.078470867 0.285943945
#> 29  0.097733148 0.007395102
#> 30  0.119930635 0.146669523
#> 31  0.068105925 0.007395102
#> 32  0.109565693 0.146669523
#> 33  0.149557859 0.146669523
#> 34  0.025178554 0.146669523
#> 35  0.014813612 0.146669523
#> 36  0.004448670 0.146669523
#> 37  0.026646156 0.146669523
#> 38  0.037011098 0.007395102
#> 39  0.119930635 0.146669523
#> 40  0.016281214 0.007395102
#> 41  0.078470867 0.007395102
#> 42  0.109565693 0.146669523
#> 43  0.035543496 0.131879319
#> 44  0.025178554 0.146669523
#> 45  0.057740983 0.007395102
#> 46  0.140660519 0.146669523
#> 47  0.119930635 0.131879319
#> 48  0.005916272 0.007395102
#> 49  0.119930635 0.131879319
#> 50  0.128827975 0.007395102
#> 51  0.099200751 0.007395102
#> 52  0.005916272 0.131879319
#> 53  0.057740983 0.131879319
#> 54  0.045908438 0.131879319
#> 55  0.035543496 0.007395102
#> 56  0.004448670 0.131879319
#> 57  0.026646156 0.131879319
#> 58  0.056273380 0.146669523
#> 59  0.045908438 0.007395102
#> 60  0.016281214 0.007395102
#> 61  0.130295577 0.146669523
#> 62  0.149557859 0.007395102
#> 63  0.109565693 0.007395102
#> 64  0.026646156 0.007395102
#> 65  0.068105925 0.007395102
#> 66  0.057740983 0.146669523
#> 67  0.047376041 0.146669523
#> 68  0.016281214 0.131879319
#> 69  0.057740983 0.131879319
#> 70  0.047376041 0.007395102
#> 71  0.005916272 0.131879319
#> 72  0.149557859 0.007395102
#> 73  0.119930635 0.146669523
#> 74  0.232477395 0.007395102
#> 75  0.097733148 0.007395102
#> 76  0.088835809 0.007395102
#> 77  0.118463033 0.131879319
#> 78  0.066638322 0.007395102
#> 79  0.192485229 0.131879319
#> 80  0.109565693 0.131879319
#> 81  0.035543496 0.131879319
#> 82  0.077003264 0.007395102
#> 83  0.211747511 0.007395102
#> 84  0.191017627 0.007395102
#> 85  0.191017627 0.007395102
#> 86  0.088835809 0.007395102
#> 87  0.004448670 0.007395102
#> 88  0.014813612 0.131879319
#> 89  0.191017627 0.007395102
#> 90  0.099200751 0.146669523
#> 91  0.005916272 0.131879319
#> 92  0.078470867 0.007395102
#> 93  0.037011098 0.007395102
#> 94  0.056273380 0.007395102
#> 95  0.068105925 0.131879319
#> 96  0.099200751 0.146669523
#> 97  0.068105925 0.007395102
#> 98  0.088835809 0.007395102
#> 99  0.016281214 0.007395102
#> 100 0.078470867 0.131879319
#> 101 0.045908438 0.131879319
#> 102 0.068105925 0.007395102
#> 103 0.066638322 0.007395102
#> 104 0.005916272 0.007395102
#> 105 0.035543496 0.146669523
#> 106 0.037011098 0.007395102
#> 107 0.087368206 0.007395102
#> 108 0.047376041 0.007395102
#> 109 0.077003264 0.007395102
#> 110 0.130295577 0.146669523
#> 111 0.068105925 0.131879319
#> 112 0.191017627 0.007395102
#> 113 0.182120287 0.007395102
#> 114 0.130295577 0.131879319
#> 115 0.087368206 0.007395102
#> 116 0.140660519 0.146669523
#> 117 0.139192917 0.146669523
#> 118 0.057740983 0.146669523
#> 119 0.037011098 0.146669523
#> 120 0.182120287 0.007395102
#> 121 0.130295577 0.131879319
#> 122 0.025178554 0.146669523
#> 123 0.068105925 0.007395102
#> 124 0.099200751 0.146669523
#> 125 0.078470867 0.131879319
#> 126 0.037011098 0.007395102
#> 127 0.128827975 0.007395102
#> 128 0.016281214 0.007395102
#> 129 0.151025461 0.146669523
#> 130 0.149557859 0.131879319
#> 131 0.035543496 0.007395102
#> 132 0.097733148 0.007395102
#> 133 0.159922801 0.131879319
#> 134 0.077003264 0.007395102
#> 135 0.047376041 0.131879319
#> 136 0.119930635 0.146669523
#> 137 0.045908438 0.007395102
#> 138 0.066638322 0.146669523
#> 139 0.087368206 0.007395102
#> 140 0.066638322 0.131879319
#> 141 0.109565693 0.146669523
#> 142 0.119930635 0.007395102
#> 143 0.140660519 0.146669523
#> 144 0.026646156 0.007395102
#> 145 0.056273380 0.007395102
#> 146 0.097733148 0.007395102
#> 147 0.088835809 0.131879319
#> 148 0.087368206 0.007395102
#> 149 0.202850171 0.131879319
#> 150 0.035543496 0.131879319
#> 151 0.078470867 0.007395102
#> 152 0.025178554 0.131879319
#> 153 0.004448670 0.131879319
#> 154 0.097733148 0.007395102
#> 155 0.077003264 0.146669523
#> 156          NA          NA
#> 157 0.057740983 0.007395102
#> 158 0.004448670 0.146669523
#> 159 0.005916272 0.007395102
#> 160 0.066638322 0.007395102
#> 161 0.004448670 0.131879319
#> 162 0.191017627 0.007395102
#> 163 0.068105925 0.146669523
#> 164 0.005916272 0.007395102
#> 165 0.016281214 0.007395102
#> 166 0.056273380 0.131879319
#> 167 0.025178554 0.007395102
#> 168 0.170287743 0.131879319
#> 169 0.014813612 0.007395102
#> 170 0.026646156 0.131879319
#> 171 0.014813612 0.007395102
#> 172 0.045908438 0.131879319
#> 173 0.066638322 0.007395102
#> 174 0.201382569 0.131879319
#> 175 0.097733148 0.007395102
#> 176 0.035543496 0.007395102
#> 177 0.066638322 0.146669523
#> 178 0.077003264 0.007395102
#> 179 0.097733148 0.007395102
#> 180 0.119930635 0.131879319
#> 181 0.025178554 0.131879319
#> 182 0.242842337 0.131879319
#> 183 0.037011098 0.131879319
#> 184 0.026646156 0.007395102
#> 185 0.118463033 0.131879319
#> 186 0.180652685 0.131879319
#> 187 0.099200751 0.146669523
#> 188 0.045908438 0.131879319
#> 189 0.016281214 0.007395102
#> 190 0.097733148 0.131879319
#> 191 0.099200751 0.007395102
#> 192 0.108098090 0.146669523
#> 193 0.128827975 0.007395102
#> 194 0.016281214 0.007395102
#> 195 0.088835809 0.007395102
#> 196 0.078470867 0.131879319
#> 197 0.005916272 0.007395102
#> 198 0.016281214 0.007395102
#> 199 0.108098090 0.131879319
#> 200 0.025178554 0.007395102
#> 201 0.016281214 0.007395102
#> 202 0.109565693 0.007395102
#> 203 0.005916272 0.131879319
#> 204 0.128827975 0.131879319
#> 205 0.005916272 0.131879319
#> 206 0.004448670 0.146669523
#> 207 0.077003264 0.131879319
#> 208 0.128827975 0.146669523
#> 209 0.068105925 0.007395102
#> 210 0.035543496 0.007395102
#> 211 0.025178554 0.131879319
#> 212 0.047376041 0.007395102
#> 213 0.068105925 0.007395102
#> 214 0.016281214 0.146669523
#> 215 0.026646156 0.007395102
#> 216 0.026646156 0.007395102
#> 217 0.222112453 0.007395102
#> 218 0.140660519 0.146669523
#> 219 0.078470867 0.146669523
#> 220 0.056273380 0.131879319
#> 221 0.047376041 0.007395102
#> 222 0.088835809 0.007395102
#> 223 0.140660519 0.007395102
#> 224 0.151025461 0.007395102
#> 225 0.242842337 0.131879319
#> 226 0.130295577 0.146669523
#> 227 0.037011098 0.007395102
#> 228 0.045908438 0.007395102
#> 

# For someone who demands reference='zero'
pzero <- function(fit)
  predict(fit, reference="sample") + sum(coef(fit) * fit$means, na.rm=TRUE)