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
cleanNAs <- function(x){ | |
if(sum(is.na(x)) == length(x)) { | |
x <- NA | |
} else | |
x <- x[!is.na(x)] | |
x | |
} | |
dat <- read.csv("testing.csv", header = TRUE) | |
dat$clean <- apply(dat, 1, cleanNAs) |
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
get.r2 <- function(mod){ | |
ll_null <- logLik(glm(model.frame(mod)[,1] ~ 1 + model.frame(mod)[, "cond"], family = "binomial")) | |
ll_full <- logLik(mod) | |
1 - ll_full/ll_null | |
} | |
#' Obtain fit stats based on best threshold | |
#' | |
#' @param mod a fitted model | |
get.coords <- function(mod, x = x){ |
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
# Load the Lock5Data package | |
library("Lock5Data") | |
# If you get an error, you need to install Lock5Data | |
# install.packages("Lock5Data") | |
################################ | |
# -- Descriptive Statistics -- # | |
################################ |
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
# lattice add-ons | |
library(lattice) | |
#' Wilkinson Dot Plot | |
#' @param x A single variable | |
wilkplot <- function(x, ...){ | |
# create the table | |
x.var <- as.numeric(names(table(x))) | |
y.var <- c(table(x)) | |
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
## ----include = FALSE, message = FALSE, warning = FALSE------------------- | |
library(tidyverse) | |
cohen.d <- function(samp1, samp2){ | |
xbar1 <- mean(samp1) | |
xbar2 <- mean(samp2) | |
n1 <- length(samp1) | |
n2 <- length(samp2) | |
s1 <- var(samp1) | |
s2 <- var(samp2) | |
pooled.sd <- sqrt(((n1 - 1)*s1 + (n2 - 1)*s2) / (n1 + n2 - 2)) |
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
## 4.2.1 Exercises ---- | |
pisa <- fread("pisa.csv", na.strings = "") | |
## 4.3.1 Exercises ---- | |
# 1. Subset all the Female students (ST004D01T) in Germany | |
germany_fem <- pisa[CNTRYID == "Germany" & ST004D01T == "Female"] | |
# 2. How many female students are there in Germany? | |
nrow(germany_fem) |
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
program exercise | |
! define constants | |
real, parameter :: pi = 3.14159 | |
real :: a = 2.0, b = 5.0, c = 3.0, x1, x2, x3 | |
! calculate values | |
x1 = (pi / 6.0) * (3 * a ** 2 + 3 * b ** 2 + c ** 2) | |
x2 = -(2*a / c) * cos(b) * sin(b) | |
x3 = (-b + sqrt(b**2 - 4 * a * c)) / 2 * a |
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
# load packages | |
library(ggplot2) | |
# true parameters ---- | |
mu_1 <- 2 | |
mu_2 <- 4 | |
sigma2_1 <- 2 | |
sigma2_2 <- 1 | |
# sample size ---- |
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
\usepackage{tcolorbox} | |
\tcbuselibrary{listings,breakable} | |
\newtcbox{\mybox}[1][red]{on line,arc=0pt,outer arc=0pt,colback=#1!10!white,colframe=#1!50!black, boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt, boxrule=0pt,bottomrule=1pt,toprule=1pt} | |
\newtcbox{\xmybox}[1][red]{on line, arc=7pt,colback=#1!10!white,colframe=#1!50!black, before upper={\rule[-3pt]{0pt}{10pt}},boxrule=1pt, boxsep=0pt,left=6pt,right=6pt,top=2pt,bottom=2pt} |