Skip to content

Commit

Permalink
Merge pull request #4 from machinelearningZH/prepare_publication
Browse files Browse the repository at this point in the history
Prepare publication
  • Loading branch information
simgraworldwide authored Nov 27, 2024
2 parents 15f56a5 + d329c6b commit 0b40c65
Show file tree
Hide file tree
Showing 267 changed files with 2,117 additions and 24,879 deletions.
15 changes: 15 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^\.ccache$
^\.github$
^tic\.R$
^LICENSE\.md$
^plausi\.Rcheck$
^plausi.*\.tar\.gz$
^plausi.*\.tgz$
^doc$
^Meta$
^vignettes
^data-raw$
^_pkgdown\.yml$
^docs$
^pkgdown$
102 changes: 102 additions & 0 deletions .github/workflows/tic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
## tic GitHub Actions template: linux-macos-windows-deploy
## revision date: 2023-12-15
on:
workflow_dispatch:
push:
branches:
- main
- cran-*
- develop
- prepare_publication
pull_request:
branches:
- main
- develop
# for now, CRON jobs only run on the default branch of the repo (i.e. usually on master)
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 4 * * *"

name: tic

jobs:
all:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
# use a different tic template type if you do not want to build on all listed platforms
- { os: windows-latest, r: "release" }
- { os: macOS-latest, r: "release", pkgdown: "true", latex: "true" }
- { os: ubuntu-latest, r: "devel" }
- { os: ubuntu-latest, r: "release" }

env:
# make sure to run `tic::use_ghactions_deploy()` to set up deployment
TIC_DEPLOY_KEY: ${{ secrets.TIC_DEPLOY_KEY }}
# prevent rgl issues because no X11 display is available
RGL_USE_NULL: true
# if you use bookdown or blogdown, replace "PKGDOWN" by the respective
# capitalized term. This also might need to be done in tic.R
BUILD_PKGDOWN: ${{ matrix.config.pkgdown }}
# use GITHUB_TOKEN from GitHub to workaround rate limits in {remotes}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
Ncpus: 4

- uses: r-lib/actions/setup-tinytex@v2
if: matrix.config.latex == 'true'

- uses: r-lib/actions/setup-pandoc@v2

- name: Install sys deps for Ubuntu
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install -y libgit2-dev libcurl4-openssl-dev

# set date/week for use in cache creation
# https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970
# - cache R packages daily
- name: "[Cache] Prepare daily timestamp for cache"
if: runner.os != 'Windows'
id: date
run: echo "date=$(date '+%d-%m')" >> $GITHUB_OUTPUT

- name: "[Cache] Restore R package cache"
if: runner.os != 'Windows'
uses: actions/cache/restore@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}

- name: "[Stage] Install"
run: Rscript -e "install.packages('tic', repos = c('https://ropensci.r-universe.dev', if (grepl('Ubuntu', Sys.info()[['version']])) {sprintf('https://packagemanager.rstudio.com/all/__linux__/%s/latest', system('lsb_release -cs', intern = TRUE))} else {'https://cloud.r-project.org'}))" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()"

- name: "[Cache] Save R package cache"
if: runner.os != 'Windows' && always()
uses: actions/cache/save@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}

- name: "[Stage] Script"
run: Rscript -e 'tic::script()'

- name: "[Stage] After Success"
run: Rscript -e "tic::after_success()"

- name: "[Stage] Upload R CMD check artifacts"
if: failure()
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
.RData
.Ruserdata
inst/doc
plausi.Rcheck/
plausi*.tar.gz
plausi*.tgz
/doc/
/Meta/
docs
11 changes: 0 additions & 11 deletions .gitlab-ci.yml

This file was deleted.

23 changes: 14 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: plausi
Type: Package
Title: popular vote forensics
Version: 0.1.0.9999
Version: 0.2.0
Authors@R: c(person(given = "Thomas",
family = "Lo Russo",
role = c("aut", "cre"),
Expand All @@ -11,21 +11,26 @@ Authors@R: c(person(given = "Thomas",
role = c("aut"),
email = "[email protected]"))
Description: Toolkit for vote and election forensics in R that allows to identify statistical anomalies in vote results.
License: GPL-2
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
purrr,
dplyr,
tidyr,
caret,
stats
caret,
stats
Depends:
R (>= 2.10)
Remotes:
r-lib/cli
r-lib/cli
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown
rmarkdown,
devtools,
kernlab,
ggplot2,
dplyr,
tidyr,
testthat (>= 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2024
COPYRIGHT HOLDER: plausi authors
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2024 plausi authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 10 additions & 15 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
# Generated by roxygen2: do not edit by hand

export(DoubleMAD)
export(DoubleMADsFromMedian)
export(RMSE)
export(cross_fun)
export(double_mad)
export(double_mad_from_median)
export(get_differences)
export(is_outlier_double_mad)
export(isnt_out_mad)
export(isnt_out_turkey)
export(isnt_out_z)
export(is_outlier_single_mad)
export(is_outlier_turkey)
export(is_outlier_z)
export(outlier_range)
export(predict_single_vote)
export(predict_votes)
export(rmse)
export(train_prediction_model)
importFrom(caret,train)
importFrom(caret,trainControl)
importFrom(dplyr,"%>%")
importFrom(dplyr,bind_cols)
importFrom(dplyr,contains)
importFrom(dplyr,ends_with)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(purrr,map2)
importFrom(purrr,map_dfr)
importFrom(stats,IQR)
importFrom(stats,as.formula)
importFrom(stats,mad)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,predict)
importFrom(stats,quantile)
importFrom(stats,reshape)
importFrom(stats,sd)
importFrom(tidyr,drop_na)
54 changes: 47 additions & 7 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
#' Test data containing past results and incomplete results for two votes
#' Test data containing past results and incomplete results for two votes.
#'
#' @description
#' Test data containing past results covering 5 years of federal and cantonal
#' votes in the canton of Zurich as well as incomplete results of two current
#' issues.
#'
#' The units presented are counting circles. Counting circles usually correspond
#' to municipalities, with the exception of the cities Zürich and Winterthur,
#' which are divided into and published as sub units.
#'
#'
#' @format A dataframe with 171 rows and 79 columns.
#' \describe{
#' \item{gemeinde}{municipality name}
#' \item{v_gemwkid}{vote id}
#' \item{Eidg1}{Yes-Share of an on going federal vote}
#' \item{Kant1}{Yes-Share of an on going cantonal vote}
#' \item{v_....}{yes shares of past votes}
#' \item{gemeinde}{name of counting circle}
#' \item{v_gemwkid}{FSO number of the municipality (for the counting circles
#' of Zürich and Winterthur, this consists of a numeric, a zero and the FSO
#' number of the municipality)}
#' \item{Eidg1}{yes-share of the current incomplete federal vote}
#' \item{Kant1}{yes-share of the current incomplete cantonal vote}
#' \item{v_....}{yes-shares of past votes}
#'}
"votedata"
#'

"vote_data"



#' Test data containing results for national votes from the canton of Zurich for
#' all Sundays from 2017-03-01 to 2020-09-27.
#'
#' @format A dataframe with 3864 rows and 16 columns.
#' \describe{
#' \item{name}{Name of the referendum.}
#' \item{id}{ID of the referendum.}
#' \item{canton_id}{ID of the canton.}
#' \item{canton_name}{Name of the canton.}
#' \item{mun_name}{Name of the municipality.}
#' \item{geoLevelParentnummer}{Geo level number of the parent geo unit, in the case of municipalities that means district number.}
#' \item{gebietAusgezaehlt}{Indicator for finalised counting status.}
#' \item{jaStimmenInProzent}{Percentage of yes-votes.}
#' \item{jaStimmenAbsolut}{Absolut number of yes-votes.}
#' \item{neinStimmenAbsolut}{Absolut number of no-votes.}
#' \item{stimmbeteiligungInProzent}{Turnout.}
#' \item{eingelegteStimmzettel}{Total number of submitted ballots.}
#' \item{anzahlStimmberechtigte}{Number of elligable voters.}
#' \item{gueltigeStimmen}{Total number of valid yes- and no-votes.}
#' \item{votedate}{Date of the vote.}
#'}
#'

"result_data"
Loading

0 comments on commit 0b40c65

Please sign in to comment.