nestauk / asf_boiler_optimisation_rct_loop Goto Github PK
View Code? Open in Web Editor NEWField RCT with Loop exploring effect of boiler optimisation advice on energy consumption.
License: MIT License
Field RCT with Loop exploring effect of boiler optimisation advice on energy consumption.
License: MIT License
Not 100% sure why, but nesting as.data.frame(unique())
doesn't work - you have a duplicated DUMMY3. It can be fixed by just unnesting the two functions (can also replace the select
and unique
with a distinct
):
userid_df = data |>
distinct(user_id) |>
as.data.frame()
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)
Just to check - you don't mind if different regions or treatment arms have different proportions of email types?
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)
)
)
This can just be write.csv(paste0(out_dir, "/allocation_data.csv"))
You can optimise lines 108-130 as follows:
data <- data |>
group_by(user_id) |>
mutate(allocation = runif(1))
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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.