Skip to content

Instantly share code, notes, and snippets.

View vanatteveldt's full-sized avatar

Wouter van Atteveldt vanatteveldt

  • VU University
  • Amsterdam
View GitHub Profile
# Annotator front-end: https://github.com/ccs-amsterdam/CCS_annotator
# R bindings: https://github.com/ccs-amsterdam/ccsAnnotator
# Please let us know if you have any bugs, ideas, or feature requests!
# (by email or using github issues)
## remotes::install_github('ccs-amsterdam/ccsAnnotator')
library(ccsAnnotator)
units = data.frame(id=1:3, text=c("The king is dead", "Long live the king", "Hurrah! hurrah! hurrah!") )
0eNq9XV1v2zoS/SsLP9t3xW8yD/cfLLDvi6JQbCURri0bstxut/B/X8r5sOyQIuewvQ8tmjSZEYdnDofk0fjn4nF7ag592w2Lh5+Ldr3vjouH//xcHNvnrt6O3xt+HJrFw+Jpe2o3i+Wiq3fjl7t6GJp+cV4u2m7T/HfxwM5floumG9qhbV5NXL748bU77R79Tz6wj9/9q18d2+75tK17/wOrx6b2br3pw/7of9v/03sdLVZmufixeFixio9+hmZ3HP/reGiazWq335y2zUosHvj5vPzkjV+ftNm0p92q2TbroW/Xq8N+24Sc2T/Uuzvxh/IOu6Z9fnncn/pxOJZ/CXgR9DE5fEyS7I0x3JuiexO4N033pnBvhu6tAIuWikU2j0UfZ6tDcHT0YRXAkVVkd7wAj4xOILwAkIzT3RUgkgkqSLieJ6ylrEIYYXQW4QXYZ3Qa4SWYpPOIKMEknUhECSYt3V0JJul8IkqWbDqfiAKocDqfyAKocDqfyAKocHppIgugwumsIkugQmcVWQIVOquoEqgY6lqgxOxa4GfWqdBiwOmEokpASScUVQBKQScUVQBKQScUVQBKQScUXQBKQS5Q9DwonQvuqOhEogsQKehEoksQqQs2wRXd3U158tw3TfeyPx2DWw7+PlnOXOaqb9bt4eM3999X3/f7zeqwPR0XM48hgo9hC7ZbwKhd9qj5bxy1rEoq+iq47fN0GEoaecM8r0cz/qHrbgjWu3dj3rR+1K8/oScRuIx82K8+Tno+u71hoKf6OKy2+3rj/ytUh96P7dbt2ylT2x1OQ9CXIPjSWb72pyHmTGYjSFbxaMpfiydFxZOUs3jyZYbxkNLBky2p80Pg/rYQmIL6gU4k0mbHQP19MXAFKxY9BqqCVyxn6d6uRHbwARvpx4fr1G1mD2yd/RTykG0Or0LISAR8zOIc3duVsC7U6CPW9K+R8/62wywhv4UvxcBKIWzvHED2St8Op+2OTT8kuP4zCnTItKFHSucMJr6aKEt2eWVuLH4
remotes::install_github("ccs-amsterdam/ccsAnnotator")
library(ccsAnnotator)
units = data.frame(id=1:3, text=c("The king is dead", "Long live the king", "Hurrah! hurrah! hurrah!") )
sentiment_question= annotation_question("Sentiment", "Is it positive or negative?",
codes = c(Negative = 'red', Neutral = 'grey', Positive = 'green'))
codingjob = create_job('Sotu sentiment',
create_units(units, id='id', text='text'),
create_codebook(sentiment_question))
@vanatteveldt
vanatteveldt / demo_maps.R
Created November 29, 2021 17:04
Demo code used in the Visualizing Maps and Networks guest lecture. [License MIT / CC-BY (your choice)]
us = tribble(~long, ~lat,
-120, 32,
-84, 32,
-78, 24,
-72, 48,
-125, 48)
ggplot(us) + geom_polygon(aes(x=long, y=lat))
library(maps)

COVID and elections

COVID and the California recall

The data

Get the data and compute cases per 100k pop.

library(tidyverse)
# Read CSV
d = read_csv("http://i.amcat.nl/covid_calif.csv")
# Create column
d = mutate(d, relcases = cases / Population * 100000)
# most/least cases?
d = arrange(d, relcases)
head(d)
[LOG 14:24:51.205] ******* Log Initiated for Kerbal Space Program - 1.10.1.2939 (LinuxPlayer) en-us *******
Kerbal Space Program - 1.10.1.2939 (LinuxPlayer) en-us
OS: Linux 5.8 Ubuntu 20.04 64bit
CPU: AMD Ryzen 5 1500X Quad-Core Processor (8)
RAM: 32106
GPU: GeForce RTX 2070 SUPER/PCIe/SSE2 (8192MB)
SM: 50 (OpenGL 4.5.0 NVIDIA 450.102.04)
RT Formats: ARGB32, Depth, ARGBHalf, Shadowmap, RGB565, ARGB4444, ARGB1555, Default, ARGB2101010, DefaultHDR, ARGB64, ARGBFloat, RGFloat, RGHalf, RFloat, RHalf, R8, ARGBInt, RGInt, RInt, BGRA32, RGB111110Float, RG32, RGBAUShort, RG16, BGRA10101010_XR, BGR101010_XR, R16
import argparse
import django
from django.db.models import QuerySet
django.setup()
from amcat.models import Query, CodingJob, Project
import logging
logging.basicConfig(level=logging.INFO, format='[%(asctime)s %(name)-12s %(levelname)-7s] %(message)s')
library(quanteda)
corp = corpus_reshape(data_corpus_inaugural, to = "paragraphs")
dfm = dfm(corp, remove_punct=T, remove=stopwords("english"))
dfm = dfm_trim(dfm, min_docfreq = 5)
library(topicmodels)
dtm = convert(dfm, to = "topicmodels")
set.seed(1)
m = LDA(dtm, method = "Gibbs", k = 10, control = list(alpha = 0.1))
% encoding: UTF-8
\RequirePackage{xkeyval}
\RequirePackage{tcolorbox}
\tcbuselibrary{skins,breakable,xparse,raster}
\RequirePackage{listings}
\RequirePackage{newfloat}
\RequirePackage{xstring}
\RequirePackage[utf8]{inputenc}
\DeclareFloatingEnvironment[fileext=ex,placement={!ht},name=Example]{ccsexample}