Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruno Rodrigues b-rodrigues

View GitHub Profile
View gist:9b29fea2f238c81146a36736d9e97c90
---
title: "The power of DRY"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#rmarkdown::render("iwalk_script.Rmd")
library(dplyr)
library(forcats)
View gist:9ed23236acce960ccec6f465403e14db
library(dplyr)
library(ggplot2)
library(lubridate)
library(COVID19)
covid <- covid19()
cases_deaths <- covid %>%
filter(iso_alpha_3 %in% c("AUT", "BEL", "BGR", "HRV",
View knitr_expand_example.Rmd
---
title: "Results of example survey"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
#rmarkdown::render("test.Rmd")
```
View survey_example.csv
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
View gist:4915812a8fa983651b3389c254f9b7cb
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)
View gist:538ae9e45fba1eee596f3de38f83ea1b
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))
}
View gist:1ea0171e373d0b4b96a9487979c7ae3a
#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
View gist:2b42b1e5bdf6b5637ab507c27c9cb2ab
# 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/
View gist:c7e4f777529e689f770f64f355f494fd
#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 Apr 17, 2021
source code to my blog post about "dealing with non-representative samples with post-stratification"
View gist:d9efe80f879f95d305cd661b63e2dee9
---
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
---