This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Packages | |
library(tidyverse) | |
library(broom) | |
# Set seed for reproducible results | |
set.seed(20200513) | |
# Data settings to simulate | |
n_units <- 100 | |
n_metrics <- 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(corrr) | |
d <- mtcars | |
stretch_triangle <- function(cordf, upper) { | |
cordf %>% shave(upper = upper) %>% stretch(na.rm = TRUE) | |
} | |
spearman <- correlate(d, method = "spearman") %>% stretch_triangle(upper = FALSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## BASE FUNCTION | |
base <- function(obj) { | |
UseMethod("base") | |
} | |
base.default <- function(obj) { | |
as.character(obj) | |
} | |
base.regex <- function(obj) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(lavaan) | |
library(semTools) | |
# Function to fit unrotated EFA with specific number of factors | |
fit_unrotated_efa <- function(n_factors) { | |
data %>% efaUnrotate(nf = n_factors, estimator = "mlr") | |
} | |
# Fit EFAs (unrotated) with a range of factors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
d <- data_frame(x = seq_len(100)) | |
d | |
#> # A tibble: 100 x 1 | |
#> x | |
#> <int> | |
#> 1 1 | |
#> 2 2 | |
#> 3 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## predict for Analysic of Variance (aov) searches for object in global environment | |
d <- datasets::mtcars | |
fit <- aov(hp ~ am * cyl, d) | |
predict(fit) | |
d <- NULL | |
predict(d) | |
## predict for Principal Components (prcomp) can't recreate new variables defined in formula | |
fit <- prcomp(~.*., mtcars[1:25, ]) | |
predict(fit, mtcars[26:32,]) |