knitr::opts_chunk$set(echo = TRUE)
Here, we'll perform some visual tests allowing the user to ensure that stat440pkg
is returning sane results.
gen.imp.resp
Let's make sure gen.imp.resp
is returning somewhat normally-distributed data.
library(stat440pkg) library(tidyr) library(ggplot2) imp.resp <- gen.imp.resp(data = multiis, num.iter = 5) gathered.data <- gather(imp.resp) p <- ggplot(gathered.data) + geom_histogram(aes(x = value), binwidth = 0.25) + facet_wrap(~ key) plot(p)
gen.latent.vars
Let's make sure gen.latent.vars
is returning somewhat normally-distributed data. First we'll do so for Bartlett scores, then Thompson regression scores.
grp.indicator <- sapply(names(multiis), FUN = function(x){strsplit(x, split = "_")[[1]][2]}) lv <- gen.latent.vars(data = multiis, grp.indicator = grp.indicator, num.iter = 5, scores = "Bartlett") gathered.data <- gather(lv) p <- ggplot(gathered.data) + geom_histogram(aes(x = value), binwidth = 0.25) + facet_wrap(~ key) plot(p)
grp.indicator <- sapply(names(multiis), FUN = function(x){strsplit(x, split = "_")[[1]][2]}) lv <- gen.latent.vars(data = multiis, grp.indicator = grp.indicator, num.iter = 5, scores = "regression") gathered.data <- gather(lv) p <- ggplot(gathered.data) + geom_histogram(aes(x = value), binwidth = 0.2) + facet_wrap(~ key) plot(p)
Here, we'll create the similar plots to those that appear in the Results section of the report, but using Thompson scores.
M <- 50 latent.datasets <- gen.latent.datasets(M, multiis, grp.indicator = grp.indicator, num.iter = 5, scores = "regression") pooled.add1 <- pool.analyses(latent.datasets, cat~comp + int, lm) pooled.add2 <- pool.analyses(latent.datasets, comp~cat + int, lm) pooled.add3 <- pool.analyses(latent.datasets, int~comp + cat, lm) signif(pooled.add1$hypothesis.test, digits = 3) signif(pooled.add2$hypothesis.test, digits = 3) signif(pooled.add3$hypothesis.test, digits = 3) library(scatterplot3d) add <- function(x) Reduce("+", x) averaged <- add(latent.datasets)/M fit <- lm(int~comp + cat, data = averaged) scplot <- scatterplot3d(averaged$comp, averaged$cat, averaged$int, main="3D Scatterplot of Latent Variables\n with Regression Plane for Int ~ Comp + Cat", angle = 120, xlab = "compartmentalization", ylab = "categorization", zlab = "integration", col.grid = "lightgrey", pch = 19, color = "lightblue") scplot$plane3d(fit, lty = "dotted") orig <- scplot$xyz.convert(averaged$comp, averaged$cat, averaged$int) plane <- scplot$xyz.convert(averaged$comp, averaged$cat, fitted(fit)) i.negpos <- 1 + (resid(fit) > 0) segments(orig$x, orig$y, plane$x, plane$y, col = c("blue", "red")[i.negpos], lty = (2:1)[i.negpos]) # ggplot2 pairs plot library(ggplot2) library(GGally) ggpairs(averaged)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.