Need help with performing disCItest (conditional independence test on discrete set) - pcalg package


I would like to apply the PC algorithm (Peter Clark) with discrete conditional independence tests, with the pcalg package. I am having a hard time understanding what to modify and I would be very happy if someone could help me out.

I have a data set (list format) of 7 variables with 10000 values each.
I have generated the data set myself and each variable takes on 8 different values (8 levels).

When I apply nlevels() function on the data set it gives me a 0 as a result.

data <- data.frame(x1s,x2s,x3s,x4s,x5s,x6s,x7s)
data <- as_tibble(data)
xnames <- c("x1","x2","x3","x4","x5","x6","x7")

v_nlevels <- sapply(X = data, FUN = nlevels)
integer_x <- sapply(X = data, FUN = function(x) as.integer(x) - 1)
xdstat <- list(dm = integer_x, nlev = v_nlevels, adaptDF = FALSE)
pc <- pc(xdstat, indepTest = disCItest(data,xdstat), labels = xnames, alpha = 0.01)

I am aware I have not defined it well. I am a beginner with R and I have spent a lot of time trying different ways to perform the CI test but I cannot find anything on the internet on how to get this working.

Perhaps I am not using a correct data format. If anyone could point out what I am doing well it would be well appreciated!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.