outcome predictor var
# Clean environment
closeAllConnections()
rm(list=ls())
# Set enviroment
setwd("~/your working directory")
# Load packages
library(bnpa)
library(bnlearn)
# Load data sets from package
data1<-dataQuantC
###################################################################################
# mount.wl.bl.list.R - Mounts a white or black list.
###################################################################################
# Load data.work
data.to.work <- data1
head(data.to.work)
# Create an empty list or fill it before start
bl <- ""
# Setting the type of var as typical "outcome" type what means it will not point to any variable
type.var <- "o"
# Setting variable "A" as "outcome" will create a black from this variable to all others
var.name <- "A"
# Creating the black list
bl <- outcome.predictor.var(data.to.work, var.name, type.var, bl)
bl
# Setting the type of var as typical "predictor" type what means it will not be point from any other variable
type.var <- "p"
# Setting variable "D" as "predictor" will create a blacklist from all others to it
var.name <- "D"
# Creating the black list
bl <- outcome.predictor.var(data.to.work, var.name, type.var, bl)
bl
# Setting variable "F" as "predictor" will create a blacklist from all others to it
var.name <- "F" # setting this variable as a tyṕically outcome
# Creating the black list
bl <- outcome.predictor.var(data.to.work, var.name, type.var, bl)
bl
# Setting variable "G" as "predictor" will create a blacklist from all others to it
var.name <- "G" # setting this variable as a tyṕically outcome
# Creating the black list
bl <- outcome.predictor.var(data.to.work, var.name, type.var, bl)
bl
# Mounting a black list in bnlearn sintax
bl <- mount.wl.bl.list(bl)
bl
# Learn the BN structure without black and white list
bn.structure <- hc(data.to.work, blacklist = bl)
# Set the name of a text to save the bn parameters
param.name <- "docbnparamHC.txt"
# Generates a BN parameters from the BN structure and write a text file with this
bn.param <- gera.bn.param(bn.structure, data.to.work, param.name)
# Set the graph name
graph.name <- "imgBNHC"
# Save the graph
mount.graph(bn.structure, bn.param, graph.name, data.to.work)
###################################################################################
RESULTS:
###################################################################################
The BN with typical outcome and predictors variables, observe the variable "A" point to none (typical outcome) and variables "D", "F" and "G" are not pointed from any variable (typical predictors):