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

Bayesian Anova updates #3071

Merged
merged 19 commits into from
Apr 23, 2019
Merged

Bayesian Anova updates #3071

merged 19 commits into from
Apr 23, 2019

Conversation

vandenman
Copy link
Contributor

Changes to Bayesian Anova, Bayesian Ancova, and Bayesian repeated measures anova.

Overview of changes

  • All three analyses use jaspResults
  • All three analyses call the same functions in commonAnovaBayesian.R
  • All three analyses now sample from the posteriors and allow for estimates + credible intervals of the posterior effects, plots of the posteriors, and posterior R-squared.
  • All three analyses allow for single model inference, i.e., selecting a single model to examine.

Known issues/ bugs:

  • Repeated measures factors (e.g., "RM factor 1") are not automatically added to the model components. This looks like a QML issue to me. Interaction effects specified as nuisance are also not properly handled (I opened an issue for this).
  • The name of the descriptives container is visible (will be fixed by Tim).
  • There could be more containers to create a nice hierarchical dependency structure.

@vandenman vandenman requested a review from TimKDJ February 28, 2019 21:17
@vandenman
Copy link
Contributor Author

Travis fails because of the network analysis.. 😕

Copy link
Contributor

@TimKDJ TimKDJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frans just updated the R framework; I'm guessing bootnet was updated and their output changed.

@TimKDJ
Copy link
Contributor

TimKDJ commented Mar 1, 2019

Before I delve deeper into your R code, can you fix the tabs/spaces? There are a lot of misaligned lines which makes it kinda hard to read. (I'm guessing the original files had different spacing and you copied some stuff?)

@AlexanderLyNL
Copy link
Contributor

Bootnet did change recently and some of the computations were fixed, which is why the output changed.

https://github.com/SachaEpskamp/bootnet/blob/master/NEWS

@AlexanderLyNL
Copy link
Contributor

Great work on the code by the way.

@vandenman
Copy link
Contributor Author

@TimKDJ sorry, the code should be more legible now!

Copy link
Contributor

@TimKDJ TimKDJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so you made lots of changes and understandably that introduces some bugs. I added code specific comments and also noted the following problems when testing:

  • If you change the Bayes Factor type then the entire table is removed and a new progress bar appears aswell (but also when you tick “Descriptives”, or “effects”…)
  • It feels strange that the progress bar runs twice when you tick “estimates”, people can’t track overall progress now
  • Descriptives table has some errors:

Screenshot 2019-04-09 at 12 57 41

  • Model averaged posteriors plot does not handle interactions very well:

Screenshot 2019-04-09 at 12 57 57

  • When you change options not related to the Analysis of Effects table (Compare to best model / % credible interval) then the table is not reused
  • If you add some fixed factors and then afterwards tick “Individual plot per level” the progress bar goes haywire
  • Colors of Model averaged posteriors don’t feel very jaspy. They’re ggplot defaults?
  • Post Hoc Test note is repeated “Note. not enough observations” also not clear to what row it points:

Screenshot 2019-04-09 at 13 12 56

  • Marginal posterior plot for RM ANOVA generates a plot per row in the dataset
  • custom y-axis label of the descriptives plot in RM ANOVA does not work
  • We have the note “Note. All models include Region” do we then also need “Null model (incl. Region)” in the table? (also in 0.9.2.)
  • Bayesian ANCOVA fails (“Error in seq.default(2, lInd, 2): wrong sign in 'by' argument”) when one covariate and one fixed factor are added and “Model averaged posteriors” is ticked:

Screenshot 2019-04-09 at 13 50 31

  • Should we also take Log(posterior odds) in post hoc tests when LogBF is ticked? (also in 0.9.2.)
  • If you try to create plots in “Single Model Inference” you cannot have a covariate in the “Specific model terms” otherwise only empty plots are generated (even when you do have a fixed factor)

JASP-Engine/JASP/R/commonAnovaBayesian.R Outdated Show resolved Hide resolved
JASP-Engine/JASP/R/commonAnovaBayesian.R Outdated Show resolved Hide resolved
JASP-Engine/JASP/R/commonAnovaBayesian.R Outdated Show resolved Hide resolved
JASP-Engine/JASP/R/commonAnovaBayesian.R Show resolved Hide resolved
ys <- ys + weights[i] * density(samples[[i]], from = fromTo[1L], to = fromTo[2L], n = n)$y
}

return(list(x = xs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set an upper bound and change the calculation if the size is too big?

Resources/Common/qml/AncovaBayesian.qml Outdated Show resolved Hide resolved
Resources/Common/qml/AncovaBayesian.qml Outdated Show resolved Hide resolved
Resources/Common/qml/AncovaBayesian.qml Outdated Show resolved Hide resolved
JASP-Engine/JASP/R/commonAnovaBayesian.R Outdated Show resolved Hide resolved
JASP-Engine/JASP/R/commonAnovaBayesian.R Outdated Show resolved Hide resolved
@vandenman
Copy link
Contributor Author

vandenman commented Apr 12, 2019

@TimKDJ I think this is ready for another review. Three things I wasn't able to fix:

  • If you add some fixed factors and then afterwards tick “Individual plot per level” the progress bar goes haywire
  • Colors of Model averaged posteriors don’t feel very jaspy. They’re ggplot defaults?
  • Post Hoc Test note is repeated “Note. not enough observations” also not clear to what row it points:

For the post hoc, there is only one footnote but it's still not shown in the table where it points to.

Oh I also still need to implement the memory-safe but slow alternative.

Copy link
Contributor

@TimKDJ TimKDJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the interface much better now :)
The progress bar flashing is still a bit funky, I'll have a look at what's happening there.

I think the main issues have been resolved and I have markedly fewer comments ;)
Aside from the in-code comments:

  • The y-axis label for the RM ANOVA doesn't seem to actually be added to the plot.

descriptivesTable$addFootnote(
symbol = "<em>Note.</em>",
message = sprintf(
"Some combinations of factors are not observed and hence omitted (%d out of %d combinations are unobserved).",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need a different specifier than %d: "Formats d and i can also be used for logical variables, which will be converted to 0, 1 or NA."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to %g because prod(...) could return a double rather than an integer. I'm not sure why it's a problem that %d accepts logicals, aside from integers. I'd rather see NA in a string than a crash in R. It's worthwhile pointing out that sprintf("%g", NA) just returns "NA", same goes for paste.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I misread the thing I quoted. But %d complained here

posteriorPlotContainer$setOptionMustContainDependency("groupPosterior", options[["groupPosterior"]])
posteriorPlotContainer$dependOn(
options = c("posteriorPlot", "modelTerms", "credibleInterval"),
optionContainsValue = options["groupPosterior"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax for this would be optionContainsValue = list(groupPosterior=options["groupPosterior"]).
Although I think you could also just add it in options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the single brackets for indexing, options["groupPosterior"] is shorthand for list(groupPosterior = options["groupPosterior"]). Still it's better to just add it to options.

@@ -822,10 +825,10 @@
df <- data.frame(x = dd$x, y = dd$y)
xName <- expression(R^2)
plot$plotObject <- JASPgraphs::PlotPriorAndPosterior(dfLines = df, xName = xName, CRI = rsqCri, drawCRItxt = FALSE)
plot$copyDependenciesFromJaspObject(jaspResults[["tableModelComparisonState"]])
plot$dependOn(jaspObject = jaspResults[["tableModelComparisonState"]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optionsFromObject

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

descriptivesPlotContainer$setOptionMustContainDependency("plotSeparateLines", options$plotSeparateLines)
descriptivesPlotContainer$setOptionMustContainDependency("plotSeparatePlots", options$plotSeparatePlots)
opts <- c("plotHorizontalAxis", "plotSeparateLines", "plotSeparatePlots")
descriptivesPlotContainer$dependOn(optionContainsValue = options[opts])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be identical to descriptivesPlotContainer$dependOn(c("plotHorizontalAxis", "plotSeparateLines", "plotSeparatePlots"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

posteriorPlotContainer$setOptionMustContainDependency("singleModelGroupPosterior",
options[["singleModelGroupPosterior"]])
posteriorPlotContainer$dependOn(options = "singleModelPosteriorPlot",
optionContainsValue = options["singleModelGroupPosterior"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value added in optionContainsValue could just be set in options: posteriorPlotContainer$dependOn(c("singleModelPosteriorPlot", "singleModelGroupPosterior"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@TimKDJ
Copy link
Contributor

TimKDJ commented Apr 18, 2019

Could you also resolve all the comments that you have incorporated so far? It's a little messy otherwise.

@TimKDJ
Copy link
Contributor

TimKDJ commented Apr 23, 2019

Anything you wish to add @vandenman? If not, I'll merge this.

@vandenman
Copy link
Contributor Author

@TimKDJ, I've got nothing further to add, go ahead!

@TimKDJ TimKDJ merged commit f97b1e3 into jasp-stats:development Apr 23, 2019
@vandenman vandenman deleted the BANOVAupdates branch August 7, 2019 08:44
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

Successfully merging this pull request may close these issues.

3 participants