kstreet13 / slingshot

Functions for identifying and characterizing continuous developmental trajectories in single-cell data.
259 stars 42 forks source link

slinghshot::predict #180

Closed apekshasingh closed 2 years ago

apekshasingh commented 2 years ago

Hi there, thanks for the package!

I was having some trouble utilizing the slingshot::predict functionality. Looks like I'm running into some trouble with glm. Any help would be appreciated. Thanks!

slingshot_new_results <- slingshot::predict(slingshot_results, newdata = newdata) Error in eval(family$initialize) : y values must be 0 <= y <= 1 traceback() 12: stop("y values must be 0 <= y <= 1") 11: eval(family$initialize) 10: eval(family$initialize) 9: glm.fit(x = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... 8: eval(call(if (is.function(method)) "method" else method, x = X, y = Y, weights = weights, start = start, etastart = etastart, mustart = mustart, offset = offset, family = family, control = control, intercept = attr(mt, "intercept") > 0L, singular.ok = singular.ok)) 7: eval(call(if (is.function(method)) "method" else method, x = X, y = Y, weights = weights, start = start, etastart = etastart, mustart = mustart, offset = offset, family = family, control = control, intercept = attr(mt, "intercept") > 0L, singular.ok = singular.ok)) 6: glm(quants.tofit ~ logdists.tofit, family = "binomial") 5: withCallingHandlers(expr, warning = function(w) if (inherits(w, classes)) tryInvokeRestart("muffleWarning")) 4: suppressWarnings({ fit <- glm(quants.tofit ~ logdists.tofit, family = "binomial") }) 3: .local(object, ...) 2: slingshot::predict(slingshot_results, newdata = newdata) 1: slingshot::predict(slingshot_results, newdata = newdata)

kstreet13 commented 2 years ago

Hi @apekshasingh ,

Thanks for bringing this to my attention! Unfortunately, I cannot reproduce this error and the error message itself is not super helpful. Is there any chance you could provide a reproducible example, possibly with (a subset of) your data?

Best, Kelly

apekshasingh commented 2 years ago

Hi thanks for your quick reply Kelly! I'm including here my original slingshot results (slingshot_results_ref.rds) and a subset of the new data I am trying to predict (new_data.rds) that gives me the posted error. Let me know if there is other information I can provide. slingshot_github_issue_submission.zip

kstreet13 commented 2 years ago

Hi @apekshasingh ,

Thanks very much! I still don't entirely know what caused this issue, but I think I managed to fix it. There was some sort of weird numerical instability thing (for some reason, the maximum value of cumsum(x)/sum(x) was slightly greater than 1):

Screen Shot 2022-04-08 at 3 45 33 PM

I added an extra line to make sure no values are above 1 and just pushed it to the develop branch, so if you need it, you can re-install from there. Otherwise, I will try to make sure this gets included in the next Bioconductor release (which is coming up pretty soon).

Thanks again! Kelly

apekshasingh commented 2 years ago

Thanks so much for your quick fix, really appreciate it, Kelly!