# NOT RUN {
# randomAsf
# ---------
# Asf generated from explicitly specified binary factors.
randomAsf(full.tt("H*I*T*R*K"))
randomAsf(full.tt("Johnny*Debby*Aurora*Mars*James*Sonja"))
# Asf generated from a specified number of binary factors.
randomAsf(full.tt(7))
# Asf generated from an existing data frame.
randomAsf(d.educate)
# Specify the outcome.
randomAsf(d.educate, outcome = "G")
# Specify the complexity.
randomAsf(full.tt(7), compl = 2)
randomAsf(full.tt(7), compl = 3:4)
# Redundancy-freeness relative to x instead of full.tt(x).
randomAsf(d.educate, outcome = "G", how = "minimal")
# Asf with multi-value factors (x must be given as a truthTab).
randomAsf(mvtt(allCombs(c(3,4,3,5,3,4))))
# Asf from fuzzy-set data (x must be given as a truthTab).
randomAsf(fstt(d.jobsecurity))
randomAsf(fstt(d.jobsecurity), outcome = "JSR")
# Generate 20 asf.
# }
# NOT RUN {
replicate(20, randomAsf(full.tt(7), compl = 2:3))
# }
# NOT RUN {
# randomCsf
# ---------
# Csf generated from explicitly specified binary factors.
randomCsf(full.tt("H*I*T*R*K*Q*P"))
# Csf generated from a specified number of binary factors.
randomCsf(full.tt(7))
# Specify the outcomes.
randomCsf(d.volatile, outcome = c("RB","SE"))
# Specify the complexity.
randomCsf(d.volatile, outcome = c("RB","SE"), compl = 2)
randomCsf(full.tt(7), compl = 3:4)
# Specify the number of asf.
randomCsf(full.tt(7), n.asf = 3)
# Csf with multi-value factors (x must be given as a truthTab).
randomCsf(mvtt(allCombs(c(3,4,3,5,3,4))))
# Generate 20 csf.
# }
# NOT RUN {
replicate(20, randomCsf(full.tt(7), n.asf = 2, compl = 2:3))
# Inverse searches
# ----------------
# === Ideal Data ===
# Draw the data generating structure. (Every run yields different
# targets and data.)
target <- randomCsf(full.tt(5), n.asf = 2)
target
# Select the cases compatible with the target.
x <- selectCases(target)
# Run CNA without an ordering.
mycna <- cna(x, maxstep = c(4, 4, 12), rm.dup.factors = FALSE)
# Extract the first 100 csf (depending on the seed, there may be
# more than 100 csf).
csfs <- csf(mycna, 100)
# Eliminate possible structural redundancies from the csf.
min.csfs <- minimalizeCsf(csfs$condition, x)$condition
# Check whether the target is completely returned.
any(unlist(lapply(min.csfs, identical.model, target)))
# === Data fragmentation (20% missing observations) ===
# Draw the data generating structure. (Every run yields different
# targets and data.)
target <- randomCsf(full.tt(7), n.asf = 2)
target
# Generate the complete data.
x <- tt2df(selectCases(target))
# Introduce fragmentation.
x <- x[-sample(1:nrow(x), nrow(x)*0.2), ]
# Run CNA without an ordering.
mycna <- cna(x, maxstep = c(4, 4, 12), rm.dup.factors = FALSE)
# Extract and minimize the first 100 csf (depending on the seed, there may be
# more than 100 csf).
csfs <- csf(mycna, 100)
min.csfs <- minimalizeCsf(csfs$condition, x)
# Check whether (a submodel of) the target is actually returned.
any(is.submodel(min.csfs$condition, target))
# === Data fragmentation and noise (20% missing observations, noise ratio of 0.05) ===
# Multi-value data.
# Draw the data generating structure. (Every run yields different
# targets and data.)
fullData <- mvtt(allCombs(c(4,4,4,4,4)))
target <- randomCsf(fullData, n.asf=2, compl = 2:3)
target
# Generate the complete data.
x <- tt2df(selectCases(target, fullData))
# Introduce fragmentation.
x <- x[-sample(1:nrow(x), nrow(x)*0.2), ]
# Introduce random noise.
x <- rbind(tt2df(fullData[sample(1:nrow(fullData), nrow(x)*0.05), ]), x)
# Run CNA without an ordering.
mycna <- mvcna(x, con = .75, cov = .75, maxstep = c(3, 3, 12), rm.dup.factors = F)
# Extract and minimize the first 100 csf (depending on the seed, there may be
# more than 100 csf).
csfs <- csf(mycna, 100)
min.csfs <- if(nrow(csfs)>0) {
as.vector(minimalizeCsf(csfs$condition, mvtt(x))$condition)
} else {NA}
# Check whether no causal fallacy (no false positive) is returned.
if(length(min.csfs)==1 && is.na(min.csfs)) {
TRUE } else {any(is.submodel(min.csfs, target))}
# }
Run the code above in your browser using DataLab