0% found this document useful (0 votes)
16 views

Chapter 1

otro capitulo

Uploaded by

zopauy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Chapter 1

otro capitulo

Uploaded by

zopauy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Introduction to

experimental design
E X P E R I M E N TA L D E S I G N I N R

Joanne Xiong
Data Scientist
Intro to experimental design
Starts with a question (hypothesis)
Collecting & analyzing the data

EXPERIMENTAL DESIGN IN R
Steps of an experiment
Planning
dependent variable = outcome

independent variable(s) = explanatory variables


Design

Analysis

EXPERIMENTAL DESIGN IN R
Key components of an experiment
Randomization
Replication

Blocking

EXPERIMENTAL DESIGN IN R
Randomization
Evenly distributes any variability in outcome due to outside factors across treatment groups

Example:
double-blind medical trials

neither patient nor doctor knows which group has been assigned

group assignment is made randomly by 3rd party

EXPERIMENTAL DESIGN IN R
Recap: t-tests
t-tests help answer research questions

data("mtcars")

t.test(x = mtcars$mpg, alternative = "two.sided", mu = 40)

library(broom)

tidy()

EXPERIMENTAL DESIGN IN R
Let's practice!
E X P E R I M E N TA L D E S I G N I N R
Replication and
blocking
E X P E R I M E N TA L D E S I G N I N R

Joanne Xiong
Data Scientist
Replication
Must repeat an experiment to fully assess variability

If we only conduct a drug efficacy experiment on one person, how can we properly
generalize those results? (We can't!)

library(dplyr)
mtcars %>%
count(cyl)

cyl n
1 4 11
2 6 7
3 8 14

EXPERIMENTAL DESIGN IN R
Blocking
Helps control variability by making treatment groups more alike

Inside of groups, differences will be minimal. Across groups, differences will be larger

One example is blocking treatment groups by sex

EXPERIMENTAL DESIGN IN R
Boxplots
# Boxplot of MPG by Car Cylinders
ggplot(mtcars, aes(x=as.factor(cyl),
y=mpg)) +
geom_boxplot(fill="slateblue",
alpha=0.2) +
xlab("cyl")

EXPERIMENTAL DESIGN IN R
Functions for modeling
Linear models

lm(formula, data, na.action,...)

One-way ANOVA model

aov(formula, data = NULL, ...)

Nested ANOVA model

anova(object,...)

EXPERIMENTAL DESIGN IN R
Let's practice!
E X P E R I M E N TA L D E S I G N I N R
Hypothesis testing
E X P E R I M E N TA L D E S I G N I N R

Joanne Xiong
Data Scientist
Breaking down hypothesis testing:
Null hypothesis:
there is no change

no difference between groups

the mean, median, or observation = a number

Alternative hypothesis:
there is a change

difference between groups

mean, median, or observation is >, <, or != to a number

EXPERIMENTAL DESIGN IN R
Power and sample size
Power: probability that the test correctly rejects the null hypothesis when the alternative
hypothesis is true.

Effect size: standardized measure of the difference you're trying to detect.

Sample size: How many experimental units you need to survey to detect the desired
difference at the desired power.

EXPERIMENTAL DESIGN IN R
Power and sample size calculations
library(pwr)
pwr.anova.test(k = 3,
n = 20,
f = 0.2,
sig.level = 0.05,
power = NULL)

Balanced one-way analysis of variance power calculation


k = 3
n = 20
f = 0.2
sig.level = 0.05
power = 0.2521043
NOTE: n is number in each group

EXPERIMENTAL DESIGN IN R
Let's practice!
E X P E R I M E N TA L D E S I G N I N R

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy