Normalize/Z-score/Scale
library(psycho)
library(tidyverse)
# Normalize all numeric variables
df <- iris %>%
psycho::normalize()
summary(df)
## Species Sepal.Length Sepal.Width Petal.Length
## setosa :50 Min. :-1.86378 Min. :-2.4258 Min. :-1.5623
## versicolor:50 1st Qu.:-0.89767 1st Qu.:-0.5904 1st Qu.:-1.2225
## virginica :50 Median :-0.05233 Median :-0.1315 Median : 0.3354
## Mean : 0.00000 Mean : 0.0000 Mean : 0.0000
## 3rd Qu.: 0.67225 3rd Qu.: 0.5567 3rd Qu.: 0.7602
## Max. : 2.48370 Max. : 3.0805 Max. : 1.7799
## Petal.Width
## Min. :-1.4422
## 1st Qu.:-1.1799
## Median : 0.1321
## Mean : 0.0000
## 3rd Qu.: 0.7880
## Max. : 1.7064
Assess
library(psycho)
results <- psycho::assess(124, mean=100, sd=15)
# Print it
print(results)
## [1] "The participant (score = 124) is positioned at 1.6 standard deviations from the mean (M = 100, SD = 15). The participant's score is greater than 94.51 % of the general population."

Bayesian Mixed Linear Model
library(psycho)
library(rstanarm)
# Create dataframe
df <- data.frame(Participant = as.factor(rep(1:50,each=2)), Condition = base::rep_len(c("A", "B"), 100), V1 = rnorm(100, 30, .2), V2 = runif(100, 3, 5))
df <- psycho::normalize(df)
# Show dataframe
kable(head(df))
1 |
A |
0.8173544 |
-0.1834544 |
1 |
B |
-0.5505681 |
-1.6831122 |
2 |
A |
-1.2760210 |
-0.0120930 |
2 |
B |
-0.2900019 |
0.3333527 |
3 |
A |
1.5021987 |
1.0535220 |
3 |
B |
-1.1998550 |
-0.7126512 |
# Fit bayesian mixed model
fit <- rstanarm::stan_lmer(V1 ~ Condition / V2 + (1|Participant), data=df)
results <- psycho::analyze(fit)
# Print summary
kable(summary(results))
(Intercept) |
55.575 |
-0.0176665 |
0.1375705 |
-0.0184814 |
0.1450662 |
-0.3127607 |
0.2708144 |
ConditionB |
55.825 |
0.0274426 |
0.1875246 |
0.0223625 |
0.1957412 |
-0.3862145 |
0.4069334 |
ConditionA:V2 |
86.825 |
0.1654395 |
0.1451932 |
0.1647602 |
0.1467532 |
-0.1231931 |
0.4546875 |
ConditionB:V2 |
86.200 |
-0.1584952 |
0.1465662 |
-0.1582316 |
0.1454779 |
-0.4416015 |
0.1235225 |
# Show text
print(results)
## [1] "We fitted a Markov Chain Monte Carlo [type] model to predict[Y] with [X] (formula =~).Priors were set as follow: [INSERT INFO ABOUT PRIORS]."
## [2] "We fitted a Markov Chain Monte Carlo [type] model to predict[Y] with [X] (formula =V1).Priors were set as follow: [INSERT INFO ABOUT PRIORS]."
## [3] "We fitted a Markov Chain Monte Carlo [type] model to predict[Y] with [X] (formula =Condition/V2 + (1 | Participant)).Priors were set as follow: [INSERT INFO ABOUT PRIORS]."
## [4] "Concerning the effect of (Intercept), there is a probability of 55.57% that its coefficient is between -0.61 and 0 (Median = -0.018, MAD = 0.14, Mean = -0.018, SD = 0.15, 95% CI [-0.31, 0.27])."
## [5] "Concerning the effect of ConditionB, there is a probability of 55.83% that its coefficient is between 0 and 0.8 (Median = 0.027, MAD = 0.19, Mean = 0.022, SD = 0.2, 95% CI [-0.39, 0.41])."
## [6] "Concerning the interaction effect between ConditionA and V2, there is a probability of 86.83% that its coefficient is between 0 and 0.75 (Median = 0.17, MAD = 0.15, Mean = 0.16, SD = 0.15, 95% CI [-0.12, 0.45])."
## [7] "Concerning the interaction effect between ConditionB and V2, there is a probability of 86.2% that its coefficient is between -0.79 and 0 (Median = -0.16, MAD = 0.15, Mean = -0.16, SD = 0.15, 95% CI [-0.44, 0.12])."
# Plot effects
plot(results)
