knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(hypegrammaR)
library(knitr)

General Notes

Your data and questionnaire must adhere to the standard xml style output from kobo otherwise this will either not work or produce wrong results.

  • column headers unchanged
  • questionnaire names unchanged
  • xml values (NOT labeled)
  • select_multiple questions have one column with all responses concatenated (separated by blank space " "), and one column for each response named [question name].[choice name]

Your sampling frame must be in the correct format: This can be checked with the check_input function of the kobostandards package (see end of vignette)

All input files are expected as csv files. You should use the hypegrammar load_*() functions to load the inputs.

data<-read.csv("../data/testdata.csv")
sf<-read.csv("../data/test_samplingframe.csv")
quest_q<-read.csv("../data/test_questionnaire_questions.csv")
quest_c<-read.csv("../data/test_questionnaire_choices.csv")
ap<-read.csv("../data/test_analysisplan.csv")

Components of an Assessment

The data

Expected Format

Example

head(data) %>% kable(format="html")

Conditions

It must adhere to standard kobo xml format - it must not contain labeled values. In general it is good practice to add the labels after analysis is completed - it must have a single row for column headers (unchanged as they come out of kobo) - it may contain additional columns that were not in the original questionnaire. It is good practice to additional new variables as additional rows to the questionnaire, specifying variable type, choices etc.

Loading

Parameters

load_data takes only one argument file, the path to the csv file.

Example

assessment_data<-load_data(file = "../data/testdata.csv")

What you get

The dataset as a data.frame

The sampling frame(s):

This is only necessary if the analysis needs to be weighted.

Expected Format

Example

head(sf)%>% kable(format="html")

Conditions

Loading

Parameters

load_samplingframe takes only one argument file, the path to the csv file.

Example

sampling_frame<-load_samplingframe(file ="../data/test_samplingframe.csv")

What you get

the sampling frame as a data.frame

The Questionnaire

Expected Format

Example

The "questions" sheet:

head(quest_q)%>% kable(format="html")

The "choices" sheet:

head(quest_c)%>% kable(format="html")

Conditions

Loading

Parameters

Example

questionnaire<-load_questionnaire(data = assessment_data,
                                  questions = "../data/test_questionnaire_questions.csv",
                                  choices = "../data/test_questionnaire_choices.csv",
                                  choices.label.column.to.use = "label::English")

What you get

The questionnaire object contains a set of functions to look up things in the questionnaire. You do not need to use them directly, but in case you want to, these are available:

kable(data.frame(`questionnaire functions` = names(questionnaire),check.names = F)) 

The Analysis Plan

Expected Format

Example

kable(head(ap),format = "html")

Conditions

Loading

Parameters

load_analysisplan takes only a single parameter file, the path to the csv file.

Example

analysisplan<-load_analysisplan(file="../data/test_analysisplan.csv")

What you get

The analysis plan as a data.frame

Verifying

Check that all your inputs match and are ready for analysis using hypegrammaR. For this, use the kobostandards package

# Once per machine

devtools::install_github("mabafaba/kobostandards")
library(kobostandards)
library(tibble)
kobostandards::check_input(data = assessment_data, questions = quest_q, choices = quest_c, samplingframe = sampling_frame, analysisplan = ap)


mabafaba/hypegrammaR documentation built on Oct. 2, 2019, 11:33 a.m.