Coder Social home page Coder Social logo

parentappdatascripts's Introduction

ParentAppDataScripts

Some R-Scripts for the cleaning and use of ParentApp data

parentappdatascripts's People

Contributors

cabrinenyona avatar lilyclements avatar margheritaphilipp avatar volloholic avatar

Watchers

 avatar

parentappdatascripts's Issues

Using `select` to group categories in the data set for tables

Currently in the Metabase analysis code, we create subsets of data to then run tables.
We want to use the select function instead.

For example,

data_baseline_survey <- with(plhdata_org_clean, data.frame(app_user_id,
                                                           Org,
                                                           rp.contact.field.survey_welcome_completed, rp.contact.field.user_gender,
                                                           rp.contact.field.user_age, rp.contact.field.household_adults, 
                                                           rp.contact.field.household_teens, rp.contact.field.household_babies,
                                                           rp.contact.field.household_children))

colnames(data_baseline_survey) <- naming_conventions(colnames(data_baseline_survey), replace = "rp.contact.field.")
two_way_table_baseline <- NULL
# to run all the "Habits" tables individually:
for (i in 3:length(data_baseline_survey)){
  two_way_table_baseline[[(i-2)]] <- two_way_table(data = data_baseline_survey,
                                                   row_var = names(data_baseline_survey)[i])
  
  # to get user IDs
  # user_id_print(names(data_baseline_survey)[i])
}
names(two_way_table_baseline) <- names(data_baseline_survey)[3:length(data_baseline_survey)]
# then to access a table:
two_way_table_baseline$`Household babies`

Can become

baseline_survey_columns <- c("rp.contact.field.survey_welcome_completed", "rp.contact.field.user_gender",
                             "rp.contact.field.user_age", "rp.contact.field.household_adults", 
                             "rp.contact.field.household_teens", "rp.contact.field.household_babies",
                             "rp.contact.field.household_children")

two_way_table_baseline <- NULL
for (i in 1:length(baseline_survey_columns)){
  two_way_table_baseline[[i]] <- two_way_table(data = plhdata_org_clean,
                                               row_var = baseline_survey_columns[i],
                                               replace = "rp.contact.field.")
}
names(two_way_table_baseline) <- baseline_survey_columns

Presumably we also want to use a map function instead of the for loop. For example,

two_way_table_baseline <- plhdata_org_clean %>%
  dplyr::select(Org, baseline_survey_columns) %>%
  purrr::map_at(baseline_survey_columns,
                two_way_table(row_var = names(.), replace = "rp.contact.field."))

(with the minor exception that I have used purrr incorrectly as it is giving an error - need to work this one out)

Renaming variables and adding variable labels to the data set

To tidy up the data set, it would be good to rename the variables. For example, for

"rp.contact.field.survey_welcome_completed"

to become

"Survey welcome completed"

This can currently be achieved with the naming_conventions function. However, does that lose information in the variable? Would we therefore want to add variable labels to the data?

Adding percentages to two-way tables

Could write in percentages for two-way tables function (as with multiple_summary_PT function) with the option of giving them by row or by column.

Row would be useful for e.g. gender (what percentage of Nontobeko users were male vs female)
Column could give info on share by organisation (e.g. what percentage of all users who have completed a workshop are from organisation x), but is probably less relevant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.