sdcTools / sdcMicro

sdcMicro
http://sdctools.github.io/sdcMicro/
79 stars 23 forks source link

Pram changes categories even when probability is zero #303

Closed matthias-da closed 4 years ago

matthias-da commented 4 years ago

This is an example from Gonzalo Mari:

base=data.frame(id=1:1000,var1=rep(1:5,200),var2=rep(1:4,250))
base$var1=as.factor(base$var1)

mat=matrix(0,nrow=5,ncol=5)
rownames(mat) <- colnames(mat) <- levels(base$var1)
mat[1,] <- c(.9, .1, 0, 0, 0)
mat[2,] <- c(.1, .8, .1, 0, 0)
mat[3,] <- c(0, .1, .8, .1, 0)
mat[4,] <- c(0, 0, .1, .8, .1)
mat[5,] <- c(0, 0, 0, .1, .9)

example <- pram(
  obj = base,
  variables = c("var1"),
  pd = mat)

print(example)
summary(example)
attr(example, "pram_params")
#########################################

The transitions are the following
    transition Frequency
 1:    1 --> 1       181
 2:    1 --> 2        17
 3:    1 --> 3         2
 4:    2 --> 1        15
 5:    2 --> 2       166
 6:    2 --> 3        17
 7:    2 --> 5         2
 8:    3 --> 2        12
 9:    3 --> 3       156
10:    3 --> 4        29
11:    3 --> 5         3
12:    4 --> 3        18
13:    4 --> 4       166
14:    4 --> 5        16
15:    5 --> 4        19
16:    5 --> 5       181

As you can see, there are some changes that have zero probability in the matrix that I include.

Thank you in advance, Regards

Saludos, Gonzalo

gonzalomari commented 4 years ago

Thank you so much for the solution, it's works fine. The only thing is that I have to load the data.table because there is a as.data.table function in the pramX that comes from this package.

bernhard-da commented 4 years ago

@gonzalomari sdcMicro depends on data.table so after loading sdcMicro it would work; also pramX is an internal (non-exported) method.