knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(hypegrammaR) library(knitr)
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")
head(data) %>% kable(format="html")
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.
load_data
takes only one argument file
, the path to the csv file.
assessment_data<-load_data(file = "../data/testdata.csv")
The dataset as a data.frame
This is only necessary if the analysis needs to be weighted.
head(sf)%>% kable(format="html")
load_samplingframe
takes only one argument file
, the path to the csv file.
sampling_frame<-load_samplingframe(file ="../data/test_samplingframe.csv")
the sampling frame as a data.frame
The "questions" sheet:
head(quest_q)%>% kable(format="html")
The "choices" sheet:
head(quest_c)%>% kable(format="html")
data
: the object that stores the data loaded abovequestions
: the path to the questions sheet as a csv filechoices
the path to the choices sheet as a csv filechoices.label.column.to.use
: the exact name of the column containing the labels that should be used. You can add an extra column with custom labels to your choices sheet if you don't want to use the choice labels from the original questionnairequestionnaire<-load_questionnaire(data = assessment_data, questions = "../data/test_questionnaire_questions.csv", choices = "../data/test_questionnaire_choices.csv", choices.label.column.to.use = "label::English")
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))
kable(head(ap),format = "html")
load_analysisplan
takes only a single parameter file
, the path to the csv file.
analysisplan<-load_analysisplan(file="../data/test_analysisplan.csv")
The analysis plan as a data.frame
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.