Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with 2 topics #54

Open
yogesh-bansal opened this issue Mar 6, 2016 · 2 comments
Open

Error with 2 topics #54

yogesh-bansal opened this issue Mar 6, 2016 · 2 comments

Comments

@yogesh-bansal
Copy link

I was using this package's createJSON() function while my topicmodel was for 2 topics and received this error
Error in stats::cmdscale(dist.mat, k = 2) : 'k' must be in {1, 2, .. n - 1}
Then I tested with reproducible example given here
http://cpsievert.github.io/LDAvis/reviews/reviews.html
by putting K=2 and keeping everything same and bumped into this error again in createJSON().

Upon seeing the source code of createJSON(), the issue is in function jsPCA().
In jsPCA(), while K=2, the dist.mat comes out to be a single value which throws an error in line
pca.fit <- stats::cmdscale(dist.mat, k = 2)

Any advice how to get past this error?

@connieshen0503
Copy link

I got the same error, do you find a way to fix this problem? k=2

@ThomasK81
Copy link

ThomasK81 commented Oct 11, 2021

I know this is a super old issue and I am not sure whether it is still needed, but I noticed some other errors occasionally with jsPCA(). This is why I rewrote the function in the following way:

jsPCA_updated <- function(phi) {
  dist.mat <- philentropy::distance(phi, 
                       method = "jensen-shannon",
                       unit = "log2")
  pca.fit <- stats::cmdscale(dist.mat, k = 2)
  data.frame(x = pca.fit[,1], y = pca.fit[,2])
}

You can then call it in the createJSON() function by setting mds.method = jsPCA_updated.

@cpsievert I haven't yet figured out why this function occasionally throws errors. I particularly noticed that it occurs more often, when using models created with the topicmodels package. Sometimes the built-in jsPCA creates one or more infinite values and stats::cmdscale throws an error. createJSON catches the error, but reports NA values instead of infinite values. If you don't mind the philentropy dependency, I'd open a pull request.

PS: Thanks for generating this package. I think it's super handy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants