Skip to content

Instantly share code, notes, and snippets.

View BERENZ's full-sized avatar

Maciej Beręsewicz BERENZ

View GitHub Profile
@BERENZ
BERENZ / symulacja.R
Created April 11, 2024 11:11
Przykład z overlap
library(nonprobsvy)
seed_for_sim <- 2024
set.seed(seed_for_sim)
## pop and sample sizes
N <- 100000 ## populacja
n_a <- N*0.7 ## proba big data o wielkosci 70%
n_b <- 10000 ## duza proba losowa
n_a1 <- 0.7 * n_a
{
"ogolem": 51.5,
"wiek": {
"18-29-lat": 38.6,
"30-39-lat": 49.5,
"40-49-lat": 55.1,
"50-59-lat": 62.4,
"60-i-wiecej-lat": 51.4
},
"plec": {
{
"NR": {
"PIS": {
"support": 1
},
"KONF": {
"support": 2
},
"TRZE": {
"support": 3
{
"126101": {
"community": "Kraków",
"county": "",
"voivodeship": "",
"frequence": 50.1,
"result": [
{
"name": "Aleskander Miszalski",
"support": 39.4,
{
"support": {
"PIS": 33.7,
"KO": 31.9,
"TRZE": 13.5,
"KONF": 7.5,
"LEW": 6.8,
"BEZP": 2.7
},
"country": {
{
"country": {
"frequence": 51.5
},
"voivods": {
"dolnoslaskie": {
"frequence": 48.3
},
"kujawsko-pomorskie": {
"frequence": 50.6
{
"support": {
"PIS": 33.7,
"KONF": 7.5,
"TRZE": 13.5,
"LEW": 6.8,
"KO": 31.9,
"BEZP": 2.7,
"INNE": 3.9
},
@BERENZ
BERENZ / 2024-ipsos-wykresy.R
Created April 7, 2024 19:56
IPSOS exit poll 2024 (wykresy)
library(jsonlite)
library(ggplot2)
library(tidyverse)
library(data.table)
library(ggrepel)
exit_poll <- read_json("https://gist.githubusercontent.com/BERENZ/d9c193c63d432f55bf7e9d3f6ec2f9fd/raw/e32e15c006563895a0d471068a17acc7c76c3546/2024-ipsos-wyniki.json")
bind_rows(
@BERENZ
BERENZ / 2024-ipsos-wyniki.json
Created April 7, 2024 19:46
IPSOS exit late poll (2024)
{
"NR": {
"PIS": {
"support": 1
},
"KONF": {
"support": 2
},
"TRZE": {
"support": 3
@BERENZ
BERENZ / chen-2023-simulation-study.R
Last active January 30, 2024 10:19
Reproducing "Dealing with undercoverage for non-probability survey samples"
## source https://www150.statcan.gc.ca/n1/pub/12-001-x/2023002/article/00005-eng.pdf
## install required packages
install.packages(c("remotes", "doSNOW", "progress", "foreach", "data.table", "sampling"))
## install nonprobsvy from github
remotes::install_github("ncn-foreigners/nonprobsvy")
## load packages
library(nonprobsvy)
library(doSNOW)
library(progress)
library(foreach)