Giter VIP home page Giter VIP logo

asf_boiler_optimisation_rct_loop's People

Contributors

jack-vines avatar oli-berry avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asf_boiler_optimisation_rct_loop's Issues

Filtering to T

We've already removed duplicate user_ids, so there should be any repeats and you can just do

userid_T_df <- data |>
  filter(treatment_num == 0 | treatment_num == 1)

(or treatment_num %in% c(0, 1))

But if you keep the deduplication then remember to either replace with distinct or take the unique out of as.data.frame (see issue 1)

Email assignment

# ~~ III. Creating assignment for email variations ~~ #

As above, you can simplify if you want:

data <- data |>
  mutate(
    rand = sample(4, nrow(data), replace=TRUE),
    email = case_when(
      treatment == "C" ~ "Control",
      rand == 1 ~ "Standard",
      rand == 2 ~ "Thermostat",
      rand == 3 ~ "TRV",
      rand == 4 ~ "Social norm"
    )
  )

Or use simple_ra from randomizr, though it isn't much neater:

data = data |>
  mutate(
    assignment = simple_ra(nrow(data), conditions = c("Standard", "Thermostat", "TRV", "Social norm")),
    email = case_when(
      treatment == "C" ~ "Control",
      TRUE ~ as.character(assignment)
    )
  )

Summary of suggestions

If you're happy using randomizr, you could replace all of Part 2 I-III with the following:

library(randomizr)

## Remove duplicate users
data <- data[!duplicated(data$user_id),]

data <- data |>
  mutate(
	## Stratify by region and assign treatments
    treatment = block_ra(blocks = data$region_id, conditions = c("T1", "T2", "C")),
	## Temporarily assign email to all users using simple randomisation
    temp.assignment = simple_ra(nrow(data), conditions = c("Standard", "Thermostat", "TRV", "Social norm")),
	## For Control group, replace with "Control"
    email = case_when(
      treatment == "C" ~ "Control",
      TRUE ~ as.character(temp.assignment)
    )
  ) |>
  ## Remove temporary assignment column
  select(-temp.assignment)

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.