Skip to content

Commit

Permalink
Merge pull request #45 from neuropsychology/0.2.0
Browse files Browse the repository at this point in the history
0.2.0_CRAN
  • Loading branch information
DominiqueMakowski committed May 1, 2018
2 parents 49c60a9 + ced72fb commit 2a18377
Show file tree
Hide file tree
Showing 93 changed files with 3,754 additions and 1,057 deletions.
25 changes: 11 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
language: r
sudo: false

r_binary_packages:
- methods
- psych
- MASS
- nFactors
- qgraph
- lmerTest
- MuMIn
- ggcorrplot
- ppcor
r_build_args: '--no-build-vignettes'
r_check_args: '--ignore-vignettes'


# Using the package cache to store R package dependencies can significantly
# speed up build times and is recommended for most builds.
cache:
- apt
- packages
cache: packages

r:
- release
- devel


warnings_are_errors: true

r_packages:
- covr
- lintr



after_success:
- Rscript -e 'library(covr); codecov()'
# - Rscript -e 'devtools::install();lintr::lint_package()'
15 changes: 10 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: psycho
Type: Package
Title: Efficient and Publishing-Oriented Workflow for Psychological Science
Version: 0.1.9
Version: 0.2.0
Authors@R: c(
person("Dominique",
"Makowski",
Expand All @@ -28,11 +28,11 @@ Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
Depends:
R (>= 3.1.0)
R (>= 3.4.0)
Imports:
methods,
ggplot2,
dplyr,
ggplot2,
tidyr,
stringr,
purrr,
Expand All @@ -47,12 +47,17 @@ Imports:
lmerTest,
coda,
emmeans,
broom
broom,
tibble,
DescTools,
pbkrtest,
BayesFactor
Suggests:
knitr,
rmarkdown,
testthat,
covr,
lme4,
plotly
plotly,
loo (>= 2.0.0)
VignetteBuilder: knitr
24 changes: 21 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Generated by roxygen2: do not edit by hand

S3method(analyze,glmerMod)
S3method(analyze,merMod)
S3method(analyze,merModLmerTest)
S3method(analyze,lm)
S3method(analyze,lmerModLmerTest)
S3method(analyze,stanreg)
S3method(find_best_model,merModLmerTest)
S3method(find_best_model,stanreg)
S3method(find_combinations,formula)
S3method(get_contrasts,glmerMod)
S3method(get_contrasts,lmerModLmerTest)
S3method(get_contrasts,stanreg)
S3method(get_predicted,stanreg)
S3method(is.mixed,stanreg)
S3method(plot,psychobject)
S3method(print,psychobject)
S3method(summary,psychobject)
Expand All @@ -27,14 +30,19 @@ export(format_string)
export(get_contrasts)
export(get_predicted)
export(hdi)
export(interpret_bf)
export(interpret_d)
export(interpret_d_posterior)
export(is.mixed)
export(is.psychobject)
export(is.standardized)
export(mellenbergh.test)
export(mpe)
export(n_factors)
export(odds_to_probs)
export(overlap)
export(power_analysis)
export(probs_to_odds)
export(standardize)
export(values)
import(coda)
Expand All @@ -46,20 +54,23 @@ import(ppcor)
import(purrr)
import(rstanarm)
import(tidyr)
importFrom(DescTools,AUC)
importFrom(MASS,ginv)
importFrom(MASS,mvrnorm)
importFrom(MuMIn,r.squaredGLMM)
importFrom(MuMIn,std.coef)
importFrom(broom,tidy)
importFrom(dplyr,bind_cols)
importFrom(emmeans,emmeans)
importFrom(ggplot2,element_text)
importFrom(ggplot2,theme)
importFrom(graphics,pairs)
importFrom(methods,slot)
importFrom(nFactors,moreStats)
importFrom(nFactors,nScree)
importFrom(psych,VSS)
importFrom(psych,corr.test)
importFrom(purrr,discard)
importFrom(purrr,keep)
importFrom(qgraph,cor_auto)
importFrom(rstanarm,bayes_R2)
importFrom(rstanarm,kfold)
Expand All @@ -68,20 +79,27 @@ importFrom(stats,as.formula)
importFrom(stats,confint)
importFrom(stats,cor)
importFrom(stats,cov)
importFrom(stats,density)
importFrom(stats,dnorm)
importFrom(stats,ecdf)
importFrom(stats,family)
importFrom(stats,formula)
importFrom(stats,mad)
importFrom(stats,median)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,na.omit)
importFrom(stats,p.adjust)
importFrom(stats,pnorm)
importFrom(stats,pt)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,rnorm)
importFrom(stats,sd)
importFrom(stats,terms)
importFrom(stats,update)
importFrom(stringr,str_to_title)
importFrom(tibble,rownames_to_column)
importFrom(utils,combn)
importFrom(utils,head)
importFrom(utils,tail)
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
# Current Dev

### Breaking changes
- Set default overlap parameter to TRUE in `analyze.stanreg`
- Remove support of lmerMod objects (linear mixed models must be fitted with lmerTest)
- Refactored get_predicted.stanreg
- Changed organization of `values` in analyzed models
- Added `subset` parameter in `standardize`
- Changed order of parameters in `dprime`
### New functions / parameters
- Added `print` for `n_factors`
- Added `overlap` (experimental) parameter to analyze.stanreg as a different index of effect existence
- Added `overlap` function
- Added `power_analysis` function.
- Added `analyze.lm` for lm objects.
- Added `interpret_bf` for bayes factor interpretation
- Added `probs_to_odds`
- Added confidence intervals (CI) to analyze for lmerTest models
- Refactored `odds_to_probs`
- Added ìs.mixed.stanreg`
- Added `keep_iterations` in `get_predicted.stanreg` (and demonstration of how to plot them in vignettes)
- Added `emotion` dataset
- Added get_contrasts methods for lme4 objects
- Added prior info in `analyze.stanreg`
- Added (exposed) `interpret_d_posterior` for Bayesian size effect interpretation
- Added `find_combinations` function
Expand Down
8 changes: 7 additions & 1 deletion R/analyze.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#' Analyze objects.
#'
#' Analyze objects.
#' Analyze objects. See the documentation for your object's class:
#' \itemize{
#' \item{\link[=analyze.stanreg]{analyze.stanreg}}
#' \item{\link[=analyze.lmerModLmerTest]{analyze.merModLmerTest}}
#' \item{\link[=analyze.glmerMod]{analyze.glmerMod}}
#' \item{\link[=analyze.lm]{analyze.lm}}
#' }
#'
#' @param x object to analyze.
#' @param ... Arguments passed to or from other methods.
Expand Down
48 changes: 33 additions & 15 deletions R/analyze.glmerMod.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
#'
#' @examples
#' library(psycho)
#' require(lme4)
#' library(lme4)
#' fit <- lme4::glmer(vs ~ mpg + (1|cyl), data=mtcars, family="binomial")
#'
#' results <- analyze(fit)
#' summary(results)
#' print(results)
#'
#' @author \href{https://dominiquemakowski.github.io/}{Dominique Makowski}
#'
Expand All @@ -29,13 +30,17 @@ analyze.glmerMod <- function(x, ...) {
# -------------
fit <- x

predictors <- all.vars(as.formula(fit@call$formula))
outcome <- predictors[[1]]
predictors <- tail(predictors, -1)

R2m <- MuMIn::r.squaredGLMM(fit)["R2m"]
R2c <- MuMIn::r.squaredGLMM(fit)["R2c"]


# Summary
# -------------
fitsum <- data.frame(lmerTest::summary(fit)$coefficients)
fitsum <- data.frame(summary(fit)$coefficients)

fitsum$Variable <- rownames(fitsum)
fitsum$Coef <- fitsum$Estimate
Expand All @@ -54,22 +59,32 @@ analyze.glmerMod <- function(x, ...) {
# Values
# -------------
# Initialize empty values
values <- list()
values$R2m <- R2m
values$R2c <- R2c
values <- list(model = list(), effects = list())
values$model$R2m <- R2m
values$model$R2c <- R2c

# Loop over all variables
for (varname in varnames) {
text <- paste(
"The effect of ", varname, " was [NOT] significant (beta = ",
if (fitsum[varname, "p"] < .1) {
significance <- ""
} else {
significance <- "not"
}


text <- paste0(
"The effect of ",
varname,
" is ",
significance,
" significant (beta = ",
format_digit(fitsum[varname, "Coef"], 2), ", SE = ",
format_digit(fitsum[varname, "SE"], 2), ", z = ",
format_digit(fitsum[varname, "z"], 2), ", p ",
format_p(fitsum[varname, "p"]), ").",
sep = ""
format_p(fitsum[varname, "p"]), ")."
)

values[[varname]] <- list(
values$effects[[varname]] <- list(
Coef = fitsum[varname, "Coef"],
SE = fitsum[varname, "SE"],
z = fitsum[varname, "z"],
Expand All @@ -82,20 +97,23 @@ analyze.glmerMod <- function(x, ...) {

# Text
# -------------
text <- c(paste(
"The overall model predicting ... successfully converged ",
text <- c(paste0(
"The overall model predicting ",
outcome,
" (formula = ",
format(fit@call$formula),
") successfully converged",
"and explained ",
format_digit(R2c * 100, 2), "% of the variance of the",
" endogen (the conditional R2). ",
"The variance explained by the fixed effects was of ",
format_digit(R2m * 100, 2), "% (the marginal R2) and the ",
"one explained by the random effects of ",
format_digit((R2c - R2m) * 100, 2), "%.",
sep = ""
format_digit((R2c - R2m) * 100, 2), "%."
))

for (varname in varnames) {
text <- c(text, paste(" -", values[[varname]]$Text))
text <- c(text, paste(" -", values$effects[[varname]]$Text))
}


Expand Down
Loading

0 comments on commit 2a18377

Please sign in to comment.