Skip to content

Instantly share code, notes, and snippets.

---
title: "Results of example survey"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#rmarkdown::render("test.Rmd")
```
Random question? Copy of Random question? Copy of Copy of Random question? Copy of Copy of Copy of Random question?
no yes yes yes
yes yes no yes
yes no no no
yes yes yes yes
no no yes yes
yes no no
no yes no no
yes yes
no yes no no
library(tidyverse)
# from https://skill-lync.com/student-projects/week-4-genetic-algorithm-295
# maximum is at x = 0.0663 y = 0.0673 f = 1
stalagmite <- function(x, y){
f1_x <- (sin(5.1*pi*x + 0.5))^6
f1_y <- (sin(5.1*pi*y + 0.5))^6
f2_x <- exp((-4*log(2))*((x-0.0667)^2)/0.64)
library(broom)
library(purrr)
library(dplyr)
library(ggplot2)
run_spurious_regression <- function(nvars = 6, nobs = 1000){
dataset <- as.data.frame(replicate(nvars, rnorm(nobs)))
tidy(lm(V1 ~ ., data = dataset))
}
#script to video https://youtu.be/bNh2WDdRleI
library(tidyverse)
# from https://skill-lync.com/student-projects/week-4-genetic-algorithm-295
# maximum is at x = 0.0663 y = 0.0673 f = 1
stalagmite <- function(x, y){
f1_x <- (sin(5.1*pi*x + 0.5))^6
f1_y <- (sin(5.1*pi*y + 0.5))^6
# Script to the video: https://youtu.be/erlWsquoHlM
set.seed(1234)
x <- abs(rnorm(1000))
in_base_R <- `^`(x, 2)
# code from https://helloacm.com/exponentiation-by-squaring/
#code to the video: https://youtu.be/hs7q64diU_c
library(tidyverse)
# prepare johnson df
data(JohnsonJohnson)
johnson <- as_tibble(matrix(JohnsonJohnson, ncol = 4, nrow= 21, byrow = TRUE)) %>%
rename(quarter1 = V1,
quarter2 = V2,
@b-rodrigues
b-rodrigues / gist:d9efe80f879f95d305cd661b63e2dee9
Created April 17, 2021 20:32
source code to my blog post about "dealing with non-representative samples with post-stratification"
---
date: 2021-04-17
title: Dealing with non-representative samples with post-stratification
tags: [R]
menu:
main:
parent: Blog
identifier: /blog/post_strat
weight: 1
---
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Layer configuration:
This function should only modify configuration layer settings."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
;; `+distribution'. For now available distributions are `spacemacs-base'
library(tidyverse)
data("population")
head(population)
pop_wide <- population %>%
pivot_wider(names_from = country, values_from = population)