Load the packages we want.
### Quietly load all packages needed
### insert your code here
library(dplyr)
library(readxl)
library(knitr)
library(tidyverse)
library(ggplot2)
library(lmtest)
library(sandwich)
In the box below, explain your experiment. Explain your experiment. What’s the idea behind your experiment, your hypothesis, study population (who did you recruit?), unit of randomization, treatment(s), and outcome metrics.
The underlying objective of my experiment was to explore the influence of loss magnitude on risk-taking behavior, specifically when the risk remains constant across different options. To illustrate, in a scenario where there is a 5% chance of losing 1,000, this risk theoretically amounts to 50. Consequently, a decision to either accept an immediate loss of 50 or take the 5% chance to lose $1,000 should be equivalent.
My hypothesis centered on the expectation that individuals in the experiment would show a decreasing inclination to opt for the 5% risk as the potential loss increased, progressing up to $10,000.
The study population for this research consisted of my MBA peers here at the UW-Madison School of Business.
To ensure randomization, I used Qualtrics to randomly present one of three questions to survey takers.
For treatment conditions I made three questions, each using the same 5% risk but at varying magnitudes.
The outcome metric would be measured by whether they pick one of the 2 options in the question “immediate loss of x amount” or “%5 risk to lose all x amount
What was the sample size, overall mean, and overall standard deviation in your experiment?
### do not change anything in {}
### Here you should load your experiment data, do any necessary data wrangling
## and calculate the requested statistics, perhaps with summary
new_directory <- "C:/Users/havil/Documents/1a Homework 1 Clinic Sales Case Study"
setwd(new_directory)
expdata = read_excel("HW 3 740 Survey for Hector essential data.xlsx")
overall_table = expdata %>%
summarise(N = n(),all_m = mean(Outcome),
all_sd = sd(Outcome),
)
## Warning: There was 1 warning in `summarise()`.
## ℹ In argument: `all_m = mean(Outcome)`.
## Caused by warning in `mean.default()`:
## ! argument is not numeric or logical: returning NA
kable(overall_table, digits = 2)
| N | all_m | all_sd |
|---|---|---|
| 14 | NA | 0.52 |
With a 14 sample size there was a .52 standard deviation.
Do treatment and control look balanced?
### do not change anything in {}
### Calculations for balance
balance_table = expdata %>% group_by(Treatment) %>%
summarise(N=n(),mean = mean(Outcome),
sd = sd(Outcome), )
## Warning: There were 3 warnings in `summarise()`.
## The first warning was:
## ℹ In argument: `mean = mean(Outcome)`.
## ℹ In group 1: `Treatment = "0"`.
## Caused by warning in `mean.default()`:
## ! argument is not numeric or logical: returning NA
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 2 remaining warnings.
kable(balance_table, digits = 2)
| Treatment | N | mean | sd |
|---|---|---|---|
| 0 | 4 | NA | 0.58 |
| 1 | 4 | NA | 0.58 |
| 2 | 6 | NA | 0.55 |
Standard deviation seems balanced and mean is unkwown based off table.
Calculate the ATE And its 95% confidence interval. Is the estimate statistically significant?
### do not change anything in {}
### Calculations for ate
outcome_table = expdata %>% group_by(Treatment) %>%
summarise(N=n(),
m = mean(Outcome),
sd = sd(Outcome)) %>%
mutate(
se = sd / sqrt(N),
lb = m - 1.96*se,
ub = m + 1.96*se)
## Warning: There were 3 warnings in `summarise()`.
## The first warning was:
## ℹ In argument: `m = mean(Outcome)`.
## ℹ In group 1: `Treatment = "0"`.
## Caused by warning in `mean.default()`:
## ! argument is not numeric or logical: returning NA
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 2 remaining warnings.
ate_table = outcome_table %>%
mutate(
ate = m - m[1],
ate_se = sqrt(se^2 + se[1]^2),ate_lb = ate - 1.96*ate_se, ate_ub = ate + 1.96+ate_se,
)
ate_table = ate_table %>%
select( Treatment, ate, ate_lb, ate_ub,
) %>%
filter(Treatment != 0)
kable(ate_table, digits = 2)
| Treatment | ate | ate_lb | ate_ub |
|---|---|---|---|
| 1 | NA | NA | NA |
| 2 | NA | NA | NA |
N/A provides inclucisive answers. At the 5% level of significance I would say this sample size would not be large enough and more experiments would be needed.
Nothing defenitive.
What is your power to detect a 10% increase in the mean of your outcome, given your sample size?
### do not change anything in {}
### Calculations for power
power.t.test(n = 12, delta = -0.2, sd = 0.52,
sig.level = 0.1)
##
## Two-sample t test power calculation
##
## n = 12
## delta = 0.2
## sd = 0.52
## sig.level = 0.1
## power = 0.232205
## alternative = two.sided
##
## NOTE: n is number in *each* group
power is at 23.2%
Imagine that you had to pay subjects to take your experiment, at a
rate of $12/hour. How many subjects would you be able to recruit with a
budget of $2,000, and what would be your power to detect a 10% increase
in the mean outcome? (Hint: you’ll need an estimate or guess of how long
it takes to
complete your experiment.)
### do not change anything in {}
### Calculations for affordability and power
power.t.test(n = 15, delta = -0.12, sd = 1,
sig.level = 0.1)
##
## Two-sample t test power calculation
##
## n = 15
## delta = 0.12
## sd = 1
## sig.level = 0.1
## power = 0.09273641
## alternative = two.sided
##
## NOTE: n is number in *each* group
At 1 minute for the survey I could recruit around 160 partipants per hour for 9.3% power.
How large a sample size would you need to detect a 10% increase in the mean of your outcome with 80% power? How much would this cost to pay your subjects? What about 95% power?
### do not change anything in {}
### Calculations for sample size and 80 or 95% [pwer]
power.t.test(delta = -0.2
, sd = 0.52, sig.level = 0.1, power = 0.8)
##
## Two-sample t test power calculation
##
## n = 84.27279
## delta = 0.2
## sd = 0.52
## sig.level = 0.1
## power = 0.8
## alternative = two.sided
##
## NOTE: n is number in *each* group
sample size of 84
Given your actual sample size, what is the minimum effect size that you can detect with 80% power? Express this as a percent of the sample mean.
### do not change anything in {}
### Calculations for power
power.t.test(n = 12, sd = 0.42, sig.level = 0.1, power = 0.8)
##
## Two-sample t test power calculation
##
## n = 12
## delta = 0.4400903
## sd = 0.42
## sig.level = 0.1
## power = 0.8
## alternative = two.sided
##
## NOTE: n is number in *each* group
44% of the mean
Did you upload your data with your canvas submission?
Yes