Error in plotting a C5.0 decision tree in R - r

I'm trying to plot my decision tree model.
cnt_c50 <- C5.0Control(CF=0.25,minCases=30,sample=0.7)
myTree <- C5.0(Y ~ X1+X2+X3+....+X30, data=data, control= cnt_c50,trials=100)
summary(myTree)
When I run summary(myTree) there is no warning, no error, everything is fine.
But when I want to visualize it : plot(myTree) , I have this error message :
Error in partysplit(varid = as.integer(i), index = index, info = k,
prob = NULL) : minimum of ‘index’ is not equal to 1 In addition:
Warning message: In min(index, na.rm = TRUE) : no non-missing
arguments to min; returning Inf
I tried to define which tree I want to visualize with plot(myTree,trial=9), and it returns this message :
Error in !all.equal(diff(sort(unique(index))), rep(1, max(index, na.rm
= TRUE) - : invalid argument type
When I try with trials=1 instead of trials=100, I have this message :
Error in if (!n.cat[i]) { : missing value where TRUE/FALSE needed
I also tried this because I saw it in a response on this website but it seems to be for CART Trees :
library(rattle)
fancyRpartplot(myTree)
and I have this error :
Error in if (model$method == "class") { : argument is of length zero
I read that it could be due to a lack of values in a category (for example a category with only 1 or 2 people) so I ran without some variables with small categories but it was the same.
I also tried this function http://r-project-thanos.blogspot.fr/2014/09/plot-c50-decision-trees-in-r.html but I am not a good programmer and I had errors too...
Did anyone have the same problem and can help me ?
Thanks a lot

Related

How do I fix a dissimilarities error in an adonis2 test in r?

I've just tried to carry out an adonis2 test using the following code
adonis2(abundance.data~Site, data=df, method="bray") as in a previous post How can I fix an error with adonis2 test?
However I keep getting this error message
Error in if (any(lhs < -TOL)) stop("dissimilarities must be non-negative") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In vegdist(as.matrix(lhs), method = method, ...) :
you have empty rows: their dissimilarities may be
meaningless in method “bray”
2: In vegdist(as.matrix(lhs), method = method, ...) :
missing values in results
Just wondering why this may be and how I can fix this issue

Error message when using psych::ICC: argument is of length zero

I would like to compute the ICC for a regression model (done using lmer function), but I always get this error message:
Error in if (n.obs < n.obs.original) message("Warning, missing data were found for ", :
argument is of length zero
Here is the function I used:
ICC(model1, missing = TRUE, alpha = .05,lmer = TRUE,check.keys = FALSE)
What I don't understand is that the ICC function should be able to handle missing values. This is why I have used the package "psych and not the package irr`...
Thank you very much for your help :)

How to fix 'unused argument' with rasch model in R

I'm using the rasch model found in the ltm library and it asks for a constraint as one of it's arguments, i try to define that my constraint is 1 (which i assume means that my discriminant is 1) and when i run the code i get an "unused argument" error which shows the whole constraint.
rasch(dep, constraint = cbind(ncol(dep) + 1, 1))
I've tried moving the argument into a new variable
disc <- cbind(ncol(LSAT) + 1, 1)
which only causes a new error after just one run
cycle k= 1
Error in if (abs(deltab) < convb) { :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(b) : argument is not numeric or logical: returning
NA
2: In if (abs(deltab) < convb) { :
the condition has length > 1 and only the first element will be used

polycor package - hetcor error in optim

I'm trying to run a factor analysis on a set of 80 dichotomous variables (1440 cases) using the hector function from the polycor package and the instructions I found here: http://researchsupport.unt.edu/class/Jon/Benchmarks/BinaryFA_L_JDS_Sep2014.pdf
Sadly, after I select just the variables interest from the rest of my dataset and run the factor analysis on them, I seem to consistently get the following error and warnings
Error in optim(0, f, control = control, hessian = TRUE, method = "BFGS") :
non-finite finite-difference value [1]
In addition: Warning messages:
1: In log(P) : NaNs produced
2: In log(P) : NaNs produced
This is with the command/when I hit the step described in the above PDF:
testMat <- hetcor(data)$cor
No idea what this means or how to proceed... Your thoughts are appreciated. Thank you!

Plotting C5.0 Tree in R

I am trying to plot a C5.0 object tree in R but it is giving the following error and I can't seem to find out how to fix it.
plot(model)
Error in partysplit(varid = as.integer(i), index = index, info = k, prob = NULL) :
minimum of ‘index’ is not equal to 1
In addition: Warning message:
In min(index, na.rm = TRUE) :
no non-missing arguments to min; returning Inf
It seems that the factors in your data frame contain spaces. I was facing the same issue, then I removed spaces from them and now it works.
for example, if a variable has factors " bad" and " good" then change them to "bad" and "good".
"The error itself is due to NA values being passed in the index vector. The root cause is probably that the factor levels are being split on spaces" Found here https://github.com/topepo/C5.0/issues/10
try this
library(rattle)
fancyRpartPlot(model)

Resources