Dear all,
I am trying to write a function for visualizing ordinal model results.
The function works fine with some values, but then I get "Error:
subscript out of bounds" even there the index should be pointing a legal
item. Code is below as well as the example of failure:
plotProb <- function(pre.mat, parts, split, titles, xlab="") {
par(mfrow = split)
n <- 1
for(k in parts) {
print("debug")
print(k)
print(n)
print(length(pre.mat))
print(pred.mat[k,])
print(titles[n])
plot(1:5, pred.mat[k,], lty=2, type="l", ylim=c(0,1), xlab=xlab,
axes=FALSE, ylab="Probability", las=1, main=titles[n])
axis(1)
axis(2)
lines(1:5, pred.mat[k+1,], lty=1)
lines(1:5, pred.mat[k+2,], lty=3)
legend("topright", c("avg. player", "5th %-tile player", "95th %-tile
player"), lty=1:3, bty="n")
n<-n+1
}
}
plotProb(q8.pred.mat.v13, c(193, 196, 199, 205, 217,241,289), c(3,3),
q8.titles3, "identification")
[1] "debug"
[1] 193
[1] 1
[1] 1920
Error in print(pred.mat[k, ]) :
error in evaluating the argument 'x' in selecting a method for
function 'print': Error: subscript out of bounds
> print(q8.pred.mat.v13[193,])
[1] 0.28478261 0.39674035 0.22653917 0.07992141 0.01201645
(However, a call, plotProb(q8.pred.mat.v13, c(1,4,7,13,25,49,97),
c(3,3), q8.titles2, "identification"), seems to work ok.)
Any hints how to tackle this are appreciated.
Petri Lankoski, petri.lankoski at iki.fi
www.iki.fi/petri.lankoski
Hi, this looks like a typo to me. The name of the argument to your
function is 'pre.mat', but you're trying to print an object called
'pred.mat' (with an extra 'd') that never appears before.
It's easier to help when you give a reproducible example that we can
execute on our own computers, as recommended by the posting guide.
Best,
Ethan
----
statisfactions.com -- The Sounds of Data and Whimsy
On Fri, May 11, 2012 at 9:41 AM, Petri Lankoski
<petri.lankoski at gmail.com> wrote:
Dear all,
I am trying to write a function for visualizing ordinal model results. The
function works fine with some values, but then I get "Error: subscript out
of bounds" even there the index should be pointing a legal item. Code is
below as well as the example of failure:
plotProb <- function(pre.mat, parts, split, titles, xlab="") {
? ? ? ?par(mfrow = split)
? ? ? ?n <- 1
? ? ? ?for(k in parts) {
? ? ? ? ? ? ? ?print("debug")
? ? ? ? ? ? ? ?print(k)
? ? ? ? ? ? ? ?print(n)
? ? ? ? ? ? ? ?print(length(pre.mat))
? ? ? ? ? ? ? ?print(pred.mat[k,])
? ? ? ? ? ? ? ?print(titles[n])
? ? ? ? ? ? ? ?plot(1:5, pred.mat[k,], lty=2, type="l", ylim=c(0,1),
xlab=xlab, axes=FALSE, ylab="Probability", las=1, main=titles[n])
? ? ? ? ? ? ? ?axis(1)
? ? ? ? ? ? ? ?axis(2)
? ? ? ? ? ? ? ?lines(1:5, pred.mat[k+1,], lty=1)
? ? ? ? ? ? ? ?lines(1:5, pred.mat[k+2,], lty=3)
? ? ? ? ? ? ? ?legend("topright", c("avg. player", "5th %-tile player",
"95th %-tile player"), lty=1:3, bty="n")
? ? ? ? ? ? ? ?n<-n+1
? ? ? ?}
}
plotProb(q8.pred.mat.v13, c(193, 196, 199, 205, 217,241,289), c(3,3),
q8.titles3, "identification")
[1] "debug"
[1] 193
[1] 1
[1] 1920
Error in print(pred.mat[k, ]) :
?error in evaluating the argument 'x' in selecting a method for function
'print': Error: subscript out of bounds
print(q8.pred.mat.v13[193,])
[1] 0.28478261 0.39674035 0.22653917 0.07992141 0.01201645
(However, a call, plotProb(q8.pred.mat.v13, c(1,4,7,13,25,49,97), c(3,3),
q8.titles2, "identification"), seems to work ok.)
Any hints how to tackle this are appreciated.
--
Petri Lankoski, petri.lankoski at iki.fi
www.iki.fi/petri.lankoski