Description Usage Arguments Details Value Examples
imputes states given state at last observation before censoring and timespecific transition rates and calculate probability weighted substitution costs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
seq_mis |
object of class |
cens.type |
character indicating the type of censoring. Must be either |
last |
optional caracter string containing state levels at last observation before censoring. |
trans.rates |
object of class |
smooth |
|
sm |
|
method |
Currently only |
prob.out |
logical indicating if imputed probabilities should be included in output. Defaults to |
diag |
logical indicating if diagonal should be printed in dist object. Defaults to |
resol.comp |
optional vector of integers. If increaments differ between calculations of dissimmilarities in complete and imputed sequences the differences can be specified for compensation. |
resol.ratio |
optional numeric specified if increaments differ between calculations of dissimmilarities in imputed and complete sequences. Defaults to |
mc.cores |
optional integer specifying the number of cores for parallel computation. |
Calculates dissimilarities for right and left censored state sequence objects using probability weighted substitution costs
d_{inf}(i,j) = ∑\limits_{t=1}^{t_{max}} ∑ Pr(i)_t Pr(j)_t^T \circ SC
Object of class 'dist'
containing dissimilarities.
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 31 32 33 34 35 36 37 | ## Creating a sequence object
data(mvad)
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school",
"training")
mvad.labels <- c("employment", "further education", "higher education",
"joblessness", "school", "training")
mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")
mvad.seq <- seqdef(mvad, 17:86, alphabet = mvad.alphabet, states = mvad.scodes,
labels = mvad.labels, xtstep = 6)
## Introducing right-censoring
addMissing <- function(x){
if(is.factor(x)) return(factor(x, levels=c(levels(x), "missing")))
return(x)}
mvad.perm <- mvad
mvad.perm <- as.data.frame(lapply(mvad.perm, addMissing))
row.perm.r <- sample(1:nrow(mvad))[1:floor(nrow(mvad)*.5)]
row.perm <- 1:nrow(mvad) %in% row.perm.r
col.perm.r <- sample(floor(ncol(mvad[,17:86])*.8):ncol(mvad[,17:86]),size = length(row.perm.r),replace = T)
for(i in 1:length(row.perm.r)){
mvad.perm[row.perm.r[i],(col.perm.r[i]+16):ncol(mvad)] <- "missing"}
perm.seq <- seqdef(mvad.perm, 17:86, alphabet = mvad.alphabet, states = mvad.scodes, missing = "missing", labels = mvad.labels, xtstep = 6)
## Computing Hamming distance in observed states
perm.seq2 <- seqdef(mvad.perm, 17:86, xtstep = 6)
sub.cost2 <- seqsubm(seqdata = perm.seq2, method = "CONSTANT")
sub.cost2["missing->",] <- sub.cost2[,"missing->"] <- 0
dist.obs <- seqdist(perm.seq2, method = "HAM", sm = sub.cost2)
## Computing Probability weighted Hamming distance in censored states:
dist.mis <- mis.cost(perm.seq, cens.type="right",sum_to_1 = F,
method = "prob",sm = "CONSTANT",smooth = F)
dist <- dist.obs + as.matrix(dist.mis$dist)
## Obtaining imputed probabilities
prob <- mis.cost(perm.seq, cens.type="right",sum_to_1 = F,
method = "prob",smooth = F, prob.out=T)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.