Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
libraryreadr
librarybnlearn
librarygRain
libraryggplot
libraryreshape
libraryforcats
librarydplyr
# Load data
data read.csvF:nd SemesterData ProcessingBayesianDatasetarchive cleanedcsv
# Convert all columns to factors
data lapplydata asfactor
data data.framedata
# levels for specific columns
levelsvehiclemovement cEnteringajunction "Getting off", "Going straight",
"Moving Backward","Other","Overtaking","Parked","Reversing",
"Stopping","Turnover","UTurn","Unknown","Waiting to go
levelsdata$Vehiclemovement levelsvehiclemovement
levelscauseofaccident cChangeLane "ChangeLane", "DriveHighOrCareless",
"DriveHighOrCareless", "DriveLeft", "DriveAlcohol",
"DriveAlcohol", "Other", "Other","MovingBackward",
"NoDistance", "NoPriority","NoPriority", "Other","Other",
"Other","Other","Other","Other","Other"
levelsdata$Causeofaccidentlevelscauseofaccident
levelsEducation cAboveHighSchool"ElementarySchool","HighSchool","Other",
"JuniorHighSchool","Unknown", "Other"
levelsdata$Education levelsEducation
levelsdrivingexperience cyryryr"Above yr"Belowyr"NoLicence",
"Unknown","Unknown"
levelsdata$Drivingexperiencelevelsdrivingexperience
levelslanes cDoubleCarriagewaymedian"OneWay","other","Twowaydivided with broken lines road marking
"TwoWaydivided with solid lines road marking"UndividedTwoWay","Unknown"
levelsdata$LanesorMedianslevelslanes
levelslightconditions cDarknesslightslit"Darknesslightsunlit",
"lightsUnlitDarkness","NoLighting","NoLighting"
levelsdata$Lightconditionslevelslightconditions
levelsroadSurface cAsphaltRoads"AsphaltsRoadswithSomeDistress","EarthRoads",
"GravelRoads","Other","Unknown"
levelsdata$RoadsurfacetypelevelsroadSurface
levelsweatherconditions cCloudy"FogOrMist","Normal","Other","Raining",
"RainingAndWindy","Snow","Unknown","Windy"
levelsdata$Weatherconditionslevelsweatherconditions
levelscollision cCollisionWithAnimals"CollisionWithPedestrians",
"CollisionWithRoadSideParkedVehicle",
"CollisionWithRoadsideObjects","FallFromVehicles","Other","RollOver","Unknown","VehicleWithVehicleCollision","WithTrain"
levelsdata$Typeofcollisionlevelscollision
strdata
summarydata
bnstructure hcdata
plotbnstructure
mmhc
hpcdata
network hcdata
graphviz.plotnetworkshape "rectangle"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started