numeric matrix extent error when plotting in R
When running the code of this example I'm getting the following error in the last line:
Error in matrix(mean(range), ncol = ncol(x), nrow = nrow(x), dimnames = dimnames(x)) : non-numeric matrix extent
However, I remember having seen other cases some months ago where the library arulesViz worked whit categorical data type.
landing.data=read.csv2("http://archive.ics.uci.edu/ml/machine-learning-databases/shuttle-landing-control/shuttle-landing-control.data",
sep=",", header=F, dec=".")
landing.data=as.data.frame(sapply(landing.data,gsub,pattern="*",replacement=10))
library(arules)
landing.system <- as(landing.data, "transactions")
rules <- apriori(landing.system, parameter=list(support=0.01, confidence=0.6))
rulesLandingManual <- subset(rules, subset=rhs %in% "V1=1" & lift>1.2)
library(arulesViz)
plot(head(sort(rulesLandingManual, by="confidence"), n=3),
method="graph",control=list(type="items"))
Doing a traceback()
after running your code gives this:
6: matrix(mean(range), ncol = ncol(x), nrow = nrow(x), dimnames = dimnames(x))
5: map(m, c(5, 20))
4: graph_arules(x, measure = measure, shading = shading, control,
...)
3: plot.rules(head(sort(rulesLandingManual, by = "confidence"),
n = 3), method = "graph", control = list(type = "items"))
2: plot(head(sort(rulesLandingManual, by = "confidence"), n = 3),
method = "graph", control = list(type = "items"))
1: plot(head(sort(rulesLandingManual, by = "confidence"), n = 3),
method = "graph", control = list(type = "items"))
So, basically the error comes from 6:
. And the error implies that any of the argument matrix(.)
are not numeric. To illustrate this:
> matrix(1:4, ncol=2)
# [,1] [,2]
# [1,] 1 3
# [2,] 2 4
> matrix(1:4, ncol="x")
# Error in matrix(1:4, ncol = "x") : non-numeric matrix extent
You see the error? I don't think there's nothing much YOU can do here as the package extends graph
, map
and matrix
to objects of class rules
. So, this probably has a lot to do with the developer side. If it is indeed the case, probably it is worth writing/contacting the developers.
I had exactly the same problem with some data I was mining rules for, and after doing some tests I found out that this error comes from the use of the sort() and head() commands when there are more rules that met the condition for quality measures than required.
For instance, in your code, you ask to plot the 3 top confidence rules in rulesLandingManual, but if you inspect(rulesLandingManual) you find that there are 216 rules with confidence 1 (max confidence) , so, when you ask to subset the top n (with n less than 217), the matrix generated in this new rules object goes messy, at least for the graph method in the plot function.
To test what I´m explaining, in your code, change n to anything between 217 to 224 (224 is the number of rules in rulesLandingManual) and it will draw the graph, while n = 216 or less will cause the mentioned error.
I don´t know if this is intended to work this way or it is a bug, I am trying to figure it out at the moment, so an explanation will come really handy.
range
is a function. Did you mean mean(range(x)), ...
?
Mean mean. Heh.
链接地址: http://www.djcxy.com/p/25040.html上一篇: 确定用户的时区
下一篇: 在R中绘制时数值矩阵范围误差