adjDevResid: Adjusted Deviance Residuals

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/DiscSurvEvaluation.R

Description

Calculates the adjusted deviance residuals. This function only supports generalized, linear models. The adjusted deviance residuals should be approximately normal distributed, in the case of a well fitting model.

Usage

1
adjDevResid(dataSet, survModelFormula, censColumn, linkFunc = "logit", idColumn = NULL)

Arguments

dataSet

Original data in short format. Must be of class "data.frame".

survModelFormula

Gives the specified relationship of discrete response and covariates. The formula is designed, that the intercepts for the time dependent base line hazards are always included. Therefore only covariates should be given in this formula. This argument is required to be of class "formula".

censColumn

Gives the column name of the event indicator (1=observed, 0=censored). Must be of type "character".

linkFunc

Specifies the desired link function in use of generalized, linear models.

idColumn

Gives the column name of the identification number of each person. The argument must be of type "character". Default NULL means, that each row equals one person (no repeated measurements).

Value

Author(s)

Thomas Welchowski [email protected]

References

Gerhard Tutz and Matthias Schmid, (2016), Modeling discrete time-to-event data, Springer series in statistics, Doi: 10.1007/978-3-319-28158-2

Gerhard Tutz, (2012), Regression for Categorical Data, Cambridge University Press

See Also

devResid, brierScore, glm, predErrDiscShort

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Example with cross validation and unemployment data 
library(Ecdat)
data(UnempDur)
summary(UnempDur$spell)

# Extract subset of data
set.seed(635)
IDsample <- sample(1:dim(UnempDur)[1], 100)
UnempDurSubset <- UnempDur [IDsample, ]

# Calculate adjusted deviance residuals for the unemployment data subset
adjDevianceResiduals <- adjDevResid (dataSet=UnempDurSubset, 
survModelFormula=spell ~ age + logwage, 
censColumn="censor1", linkFunc="logit", idColumn=NULL)
adjDevianceResiduals

# Exclude outliers
adjDevResidWoOut <- adjDevianceResiduals$Output$AdjDevResid [
adjDevianceResiduals$Output$AdjDevResid < 
quantile(adjDevianceResiduals$Output$AdjDevResid, prob=0.9) & 
adjDevianceResiduals$Output$AdjDevResid > 
quantile(adjDevianceResiduals$Output$AdjDevResid, prob=0.1)]

# Compare nonparametric density estimate of adjusted deviance residuals 
# with adapted normal distribution
plot(density(adjDevResidWoOut), xlim=c(-10,10), 
main="Density comparison: Normal vs nonparametric estimate", lwd=2, las=1, col="red")
dnorm1 <- function (x) {dnorm (x, mean=mean(adjDevResidWoOut), sd=sd(adjDevResidWoOut))}
curve (dnorm1, n=500, add=TRUE, col="black", lwd=2)
legend("topright", legend=c("Normal", "Nonpar"), lty=1, lwd=2, col=c("black", "red"))

Example output

Loading required package: Ecfun

Attaching package: 'Ecfun'

The following object is masked from 'package:base':

    sign


Attaching package: 'Ecdat'

The following object is masked from 'package:datasets':

    Orange

   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.000   2.000   5.000   6.248   9.000  28.000 
  [1]     1.9696     2.0085     5.5838     0.4669     3.2664     2.7905
  [7]     1.5965     0.1373     5.2509  7617.9555     2.2097  6417.4480
 [13]     2.7362     2.9369     0.1100     3.6473     1.8861     3.1132
 [19]     1.5427     0.5951     8.8769     2.0917     3.0569     0.8149
 [25]     2.9470     2.6151     1.4209     0.1192     4.4643     2.1301
 [31]     1.3005  9862.3460     0.3100     1.0613     4.4310     0.0416
 [37]  1641.3815     0.1154  3402.7168     3.8206     1.6383     2.9117
 [43]    -0.0645     1.6334     1.9907     1.5578     3.9920     2.5605
 [49]     2.5480     1.7482     1.0094     0.5630     2.3457  8690.9418
 [55]     3.4401  7696.7511     2.9459     2.1632     0.5681     0.5616
 [61]     1.4049     3.9214     1.4581     1.7215     1.4324     3.0116
 [67]     1.9914     2.5543     1.6663     0.7554     2.2912     1.2061
 [73]     1.1563     2.8790     2.9589     1.9374     2.3124     0.4212
 [79]     1.7194     1.5647     1.4363     1.5430     1.0284     6.6270
 [85]     1.8865  2172.9039     1.3926    -0.3689     0.3883     3.9861
 [91] 14046.6548     3.0766     1.8889     4.5997     3.9710     0.9432
 [97]     2.6025     2.3155  1831.1545     1.8334

discSurv documentation built on Aug. 4, 2018, 1:01 a.m.