Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to make a bayesian network in R . I am stating summary of my data and code in R . but the
I am trying to make a bayesian network in R I am stating summary of my data and code in R but the result of my Bayesian network is seems weird and incorrect.
Please send me corrected code here.
summarydata
Age Band of Driver Sex of Driver Educational Level Driving Experience
: Female : Above high school : yr :
: Male : Elementary school :yr :
Over : Unknown: High school : Above yr:
Under : Illiterate : yr :
Unknown : Junior high school: Below yr :
Unknown : Unknown :
Writing & reading : Other :
Types of Junction Road Surface Type Light Conditions
Y Shape : Asphalt roads : Darkness lights lit :
No junction: Asphalt roads with some distress: Darkness lights unlit:
Crossing : Earth roads : Darkness no lighting :
Unknown : Gravel roads : Daylight :
Other : Other :
O Shape : Unknown :
Other :
Weather Conditions Type of Collision Vehicle Movement
Normal : Vehicle with vehicle collision : Going straight :
Raining: Collision with roadside objects: Other :
Other : Collision with pedestrians : Moving Backward:
Unknown: Rollover : Reversing :
Cloudy : Collision with animals : Turnover :
Windy : Unknown : Getting off :
Other: Other : Other :
Cause of Accident Accident Severity
ChangeLane : Light :
NoDistance : Serious:
NoPriority :
DriveHighOrCareless:
Other :
MovingBackward :
Other :
Code: libraryreadr
librarybnlearn
librarygRain
libraryggplot
libraryreshape
libraryforcats
librarydplyr
data read.csvF:nd SemesterData ProcessingBayesianDatasetarchive cleanedcsv
data lapplydata asfactor
data data.framedata
levelsMovement cEnteringajunction "Getting off", "Going straight",
"Moving Backward","Other","Overtaking","Parked","Reversing"
"Stopping","Turnover","UTurn","Unknown","Waiting to go
levelsdata$Vehiclemovement cEntering a junction", "Getting off", "Going straight",
"Moving Backward", "Other", "Overtaking","Parked","Reversing"
"Stopping","Turnover","UTurn","Other","Waiting to go
levelsdata$Causeofaccident cChangeLane "ChangeLane", "DriveHighOrCareless",
"DriveHighOrCareless", "DriveLeft", "DriveAlcohol",
"DriveAlcohol", "Other", "Other","MovingBackward",
"NoDistance", "NoPriority","NoPriority", "Other","Other",
"Other","Other","Other","Other","Other"
# Convert the "Accidentseverity" column to character
data$Accidentseverity ascharacterdata$Accidentseverity
# Convert the "Accidentseverity" column to numeric
data$Accidentseverity asnumericdata$Accidentseverity
# Now, use the cut function
data$Accidentseverity cutdata$Accidentseverity, breaks c labels cLight "Serious"
data subsetdata select cVehicledriverrelation,LanesorMedians,Pedestrianmovement
data naomitdata
data data mutateifisnumeric, ~ifelseisna mean narm TRUE
columnnames cAge Band of Driver", "Sex of Driver", "Educational Level", "Driving Experience","Types of Junction",
"Road Surface Type", "Light Conditions", "Weather Conditions", "Type of Collision","Vehicle Movement", "Cause of Accident", "Accident Severity"
colnamesdata columnnames
summarydata
tabudata
mmhcdata
hpcdata
# Create a Bayesian network structure using the 'hill climbing' algorithm
network hcdata
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