This file contains hidden or 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
# Code below demonstrates similar/same results from SEMinR and cSEM for given model | |
# Needed changing default value of .disattenuate for cSEM | |
# Response to: https://www.reddit.com/r/rstats/comments/1fy42vy/structural_equation_model_results_differ_when/ | |
library(seminr) | |
library(cSEM) | |
nck <- corp_rep_data | |
data <- MASS::mvrnorm(1000,mu = rep(0,37),Sigma =diag(1,37)) | |
data <- cbind(mobi, corp_rep_data[1:250,3:17]) | |
colnames(data) <- c(multi_items("A", 1:3), |
This file contains hidden or 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
# Unstandardizes construct scores of an estimated SEMinR model | |
# (Based on rescale function of plspm) | |
# usage: | |
# my_model <- estimate_pls(...) | |
# ustd <- unstandardize(my_model) | |
unstandardize_scores <- function(pls_model) { | |
construct_names <- seminr:::construct_names(pls_model$smMatrix) | |
construct_names -> . | |
sapply(., seminr:::items_of_construct, model=pls_model) -> . |
This file contains hidden or 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(seminr) | |
comp1_items <- multi_items("IMAG", 1:5) | |
comp2_items <- multi_items("CUEX", 1:3) | |
comp3_items <- multi_items("CUSA", 1:3) | |
mobi_mm <- constructs( | |
# Three first-order composites | |
composite("Comp1", comp1_items), | |
composite("Comp2", comp2_items), |
This file contains hidden or 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(seminr) | |
image_items <- multi_items("IMAG", 1:5) | |
exp_items <- multi_items("CUEX", 1:3) | |
items <- c(image_items, exp_items) | |
almost_items <- items[-1] | |
eca_mm <- constructs( |
This file contains hidden or 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
# plot_regr_rsq(points) plots points and regression | |
# | |
# You can supply the following parameter: | |
# points - dataframe of x,y points to plot | |
plot_regr_rsq <- function(points) { | |
if (nrow(points) == 0) { | |
plot(NA, xlim=c(-5,50), ylim=c(-5,50), xlab="x", ylab="y") | |
return() | |
} | |
plot(points, xlim=c(-5,50), ylim=c(-5,50), pch=19, cex=2, col="gray") |
This file contains hidden or 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
# OOP | |
module Scrambler | |
def scramble | |
json_output = to_json | |
json_output.chars.sample(json_output.length).join | |
end | |
end | |
class Student | |
include Scrambler |
This file contains hidden or 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
docs <- c("OECD", "GDPR", "FTC") | |
# Functions to create: | |
pdf_to_df <- function(doc_name) { | |
filename <- paste(doc_name, ".txt") | |
#...return a dataframe | |
data.frame() | |
} | |
create_bigrams <- function(doc_df) { data.frame() } |
This file contains hidden or 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_url = "http://api.githbub.com/v1" | |
def commits_history | |
repo_username = "leoli0320" | |
repo_name = "my_fav_repo" | |
api_endpoint = [base_url, repo_username, repo_name, 'commits'].join('/') | |
req_params = {} |
This file contains hidden or 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
# Visualize the confidence intervals of samples drawn from a population | |
# e.g., | |
# visualize_sample_ci(sample_size=300, distr_func=rnorm, mean=50, sd=10) | |
# visualize_sample_ci(sample_size=300, distr_func=runif, min=17, max=35) | |
visualize_sample_ci <- function(num_samples = 100, sample_size = 100, | |
pop_size=10000, distr_func=rnorm, ...) { | |
# Simulate a large population | |
population_data <- distr_func(pop_size, ...) | |
pop_mean <- mean(population_data) | |
pop_sd <- sd(population_data) |
This file contains hidden or 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
require 'dry-monads' | |
include Dry::Monads::Maybe::Mixin |
NewerOlder