Question: R studio help. I am trying to create a predictive model using markov chains and R Studio. I am using a dataset called veteranbenefits which

R studio help. I am trying to create a predictive model using markov chains and R Studio. I am using a dataset called "veteranbenefits" which has State.Name, Percent.of.Veterans.who.used.GIBill.Education.Benefits, Number.of.Education.Benefit.Recipients, Veteran.population, and Year (over the course of 5 years 2010-2015). I am having a hard time writing out the code to have it predict which state will most likely have a higher probability of veterans using their GI Bill benefits compared to others. I had previously received help but I am now getting this repeated error "Error in dimnames(x)- dn :
length of 'dimnames' [2] not equal to array extent." This is the code and a preview of the dataset. Could my dataset be the issue? Thank you again for any help.
library(dplyr)
library(markovchain)
veteranbenefits - read.csv("veteranbenefits.csv")
veteranbenefits - na.omit(veteranbenefits)
transition_matrix - veteranbenefits %>%
group_by(State.Name, Year)%>%
summarise(transition_prob = sum(Percent.of.Veterans.who.used.GI.Bill.Education.Benefits)/
sum(Percent.of.Veterans.who.used.GI.Bill.Education.Benefits))
transition_matrix - pivot_wider(transition_matrix, names_from = "Year", values_from = "transition_prob")
transition_matrix[is.na(transition_matrix)]-0
markov_model - new("markovchain", states = unique(veteranbenefits$State.Name),
transitionMatrix = as.matrix(transition_matrix[,-1]))
predicted_probabilities - steadyStates(markov_model)
highest_state - names(predicted_probabilities)[which.max(predicted_probabilities)]
print(highest_state)
R studio help. I am trying to create a predictive

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 Accounting Questions!