Question: I am trying to create Bayesian network in R and inference. I am not sure if my bayesian network is correct or wrong. But somehow

I am trying to create Bayesian network in R and inference. I am not sure if my bayesian network is correct or wrong. But somehow it does not look good. I am sharing my code here. please create a inference now. # Load necessary libraries
library(readr)
library(bnlearn)
library(gRain)
library(ggplot2)
library(reshape2)
library(forcats)
library(dplyr)
# Load data
data <- read.csv("F:/2nd Semester/Data Processing/Bayesian/Dataset/archive (2)/cleaned.csv")
# Convert all columns to factors
data <- lapply(data, as.factor)
data <- data.frame(data)
# levels for specific columns
levels_vehiclemovement = c("Enteringajunction", "Getting off", "Going straight",
"Moving Backward","Other","Overtaking","Parked","Reversing",
"Stopping","Turnover","U-Turn","Unknown","Waiting to go")
levels(data$Vehicle_movement)= levels_vehiclemovement
levels_causeofaccident = c("ChangeLane", "ChangeLane", "DriveHighOrCareless",
"DriveHighOrCareless", "DriveLeft", "DriveAlcohol",
"DriveAlcohol", "Other", "Other","MovingBackward",
"NoDistance", "NoPriority","NoPriority", "Other","Other",
"Other","Other","Other","Other","Other")
levels(data$Cause_of_accident)=levels_causeofaccident
levels_Education = c("AboveHighSchool","ElementarySchool","HighSchool","Other",
"JuniorHighSchool","Unknown", "Other")
levels(data$Education)= levels_Education
levels_drivingexperience =c("1-2yr","2-5yr","5-10yr","Above 10yr","Below1yr","NoLicence",
"Unknown","Unknown")
levels(data$Driving_experience)=levels_drivingexperience
levels_lanes= c("DoubleCarriageway(median)","OneWay","other","Twoway(divided with broken lines road marking)",
"TwoWay(divided with solid lines road marking)","UndividedTwoWay","Unknown")
levels(data$Lanes_or_Medians)=levels_lanes
levels_lightconditions = c("Darknesslightslit","Darknesslightsunlit",
"lightsUnlitDarkness","NoLighting","NoLighting")
levels(data$Light_conditions)=levels_lightconditions
levels_roadSurface = c("AsphaltRoads","AsphaltsRoadswithSomeDistress","EarthRoads",
"GravelRoads","Other","Unknown")
levels(data$Road_surface_type)=levels_roadSurface
levels_weatherconditions = c("Cloudy","FogOrMist","Normal","Other","Raining",
"RainingAndWindy","Snow","Unknown","Windy")
levels(data$Weather_conditions)=levels_weatherconditions
levels_collision = c("CollisionWithAnimals","CollisionWithPedestrians",
"CollisionWithRoadSideParkedVehicle",
"CollisionWithRoadsideObjects","FallFromVehicles","Other","RollOver","Unknown","VehicleWithVehicleCollision","WithTrain")
levels(data$Type_of_collision)=levels_collision
str(data)
summary(data)
bn_structure <- hc(data)
plot(bn_structure)
mmhc
h2pc(data)
network = hc(data)
graphviz.plot(network,shape = "rectangle")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!