Hi there,

I´ve a question concerning the nnet package in the area of survival analysis: 
what is the final value, which is computed to fit the model with the following 
nnet-c
all:

net <- nnet(cat~x, 
        data=d, 
        size=2, 
        decay=0.1,
        censored=TRUE, 
        maxit=20, 
        Wts=rep(0,22), 
        Hess=TRUE) 

where cat is a matrix with a row for each record and one column for each 
possible time-value and x another explanatory variable.
Something like that:

0 6 17 20 28 37
[1,] 0 0  0  0  0  1
[2,] 1 0  0  0  0  0
[3,] 0 0  1  1  1  1
[4,] 0 1  0  0  0  0
...

where 0,6,17,... are the time values and record 1 has an event in time period 
37 and record 3 is censored in time period 20.


I tried to reproduce the final value with this term:

tmp <- rowSums(cat*summary(net)$fitted.values)
repFinalValue <- sum(-log(tmp))

but got the value 21.65438 instead of 21.71108. Is this only a rounding error 
or what´s wrong with my formula?

My whole test example is printed below.


Thanks,

Andrea.


# Some tests ...
# 
###############################################################################

require(survival)
require(nnet)

# training data
d <- matrix(nrow=20, ncol=3, dimnames=list(c(),c("time", "status", "x")))
d[,"time"] <- c(17,6,37,0,6,28,0,6,20,0,17,6,37,0,6,28,0,6,20,0)
d[,"status"] <- rep(c(0,1),5,each=2)
d[,"x"] <- 
c(0.27,0.27,0.49,0.49,0.61,0.70,0.78,0.78,0.84,0.86,0.27,0.27,0.49,0.49,0.61,0.70,0.78,0.78,0.84,0.86)

# compute cat-variable
cat <- computeCatVector(d, "time", "status") #     =>     a matrix with one row 
for each row in d and a column for each distinct time value in d
                                             #        generated values for each 
row in d:    
                                             #        if status = 1 => 1 in the 
time-Col, 0 otherwise
                                             #        if status = 0 => 1 from 
the time-Col till the last column, 0 before

# here: 
#0 6 17 20 28 37
#[1,] 0 0  0  0  0  1
#[2,] 1 0  0  0  0  0
#[3,] 0 0  1  1  1  1
#[4,] 0 1  0  0  0  0
#...

# nnet for survival analysis
net <- nnet(cat~x, 
        data=d, 
        size=2, 
        decay=0.1,
        censored=TRUE, 
        maxit=20, 
        Wts=rep(0,22), 
        Hess=TRUE) 

# reproduce the final value
tmp <- rowSums(cat*summary(net)$fitted.values)
repFinalValue <- sum(-log(tmp))

print(paste("Difference in finale value: mine vs. the nnet-final value:", 
repFinalValue, "vs.",summary(net)$value)) 


# the function to calculate the cat-matrix from time and status information of 
survival data
computeCatVector <- function(d, timeCol, statusCol){
    # init some values
    l <- length(unique(d[,timeCol]))
    n <- length(d[,statusCol])
    cols <- as.character(sort(unique(d[,timeCol])))
    
    cat <- matrix(rep(0,l*n), ncol=l, dimnames=list(c(),cols))
    
    for (i in 1:n) {
        for (x in cols) {
            # DS mit Ereignis
            if(d[i,timeCol]==x & d[i,statusCol]==1){
                cat[i,x] <- 1
            }
            # DS mit Zensur
            if(as.numeric(as.character(d[i,timeCol]))<=as.numeric(x) & 
d[i,statusCol]==0){
                cat[i,x] <- 1
            }
        }
    }
    
    cat    
}



      
        [[alternative HTML version deleted]]

______________________________________________
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