30
Groupwise comparison of continuous variables in 2012-11-26 @HSPH Kazuki Yoshida, M.D. MPH-CLE student FREEDOM TO KNOW

Groupwise comparison of continuous data

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Groupwise comparison of continuous data

Groupwise comparison of continuous variables in

2012-11-26 @HSPHKazuki Yoshida, M.D. MPH-CLE student

FREEDOMTO  KNOW

Page 2: Groupwise comparison of continuous data

Group Website is at:

http://rpubs.com/kaz_yos/useR_at_HSPH

Page 3: Groupwise comparison of continuous data

n Introduction

n Reading Data into R (1)

n Reading Data into R (2)

n Descriptive, continuous

n Descriptive, categorical

n Deducer

n Graphics

Previously in this group

Group Website: http://rpubs.com/kaz_yos/useR_at_HSPH

Page 4: Groupwise comparison of continuous data

Menu

n Groupwise comparison of continuous variables

Page 5: Groupwise comparison of continuous data

Ingredients

n one group vs null hypothesis

n two group comparison

n multi-group comparison

n Distribution-free alternative for each

n Creating a new variable

n t.test()

n wilcox.test()

n anova(lm())

n kruskal.test()

n BSDA::SIGN.test()

Statistics Programming

Page 6: Groupwise comparison of continuous data

Open R Studio

Page 7: Groupwise comparison of continuous data

BSDAInstall and Load

Page 9: Groupwise comparison of continuous data

Read in BONEDEN.DAT.txt

Name it bone

Bone density in twins with discordant smoking exposure

Page 10: Groupwise comparison of continuous data

bone[1:15 , 1:12]

Extract 1st to 15th rows Extract 1st to 12th columns

Indexing: extraction of data from data frame

Don’t forget commaColon in between

Page 11: Groupwise comparison of continuous data

age vector within bone data frame

Page 12: Groupwise comparison of continuous data

bone$age

Extracted as a vector

Page 13: Groupwise comparison of continuous data

bone$fn.diff <- bone$fn1 - bone$fn2

Creating a new variablenew variable subtraction

alternatively:bone <- within(bone, {

fn.diff <-fn1 - fn2})

Page 14: Groupwise comparison of continuous data

t.testt.test(bone$fn.diff, mu = 0)

One-sample t-test

Page 15: Groupwise comparison of continuous data

t.testt.test(bone$fn1, bone$fn2, paired = TRUE)

Paired t-test

Page 16: Groupwise comparison of continuous data

t.testt.test(age ~ zyg, data = bone, var.equal = TRUE)

Independent two group

comparison

Page 17: Groupwise comparison of continuous data

outcome ~ predictor

formula

Page 18: Groupwise comparison of continuous data

age ~ zyg

In the case of t-test

continuous variable to be compared

grouping variable to separate groups

Page 19: Groupwise comparison of continuous data

var.testvar.test(age ~ zyg, data = bone)

Variance comparison

(F-test)

Page 20: Groupwise comparison of continuous data

tsum.testtsum.test(mean.x = 51.38, s.x = 10.74, n.x = 21, mean.y = 46.20, s.y = 12.48, n.y = 20, var.equal = TRUE)

t-test with summary data BSDA package

Page 21: Groupwise comparison of continuous data

Distribution-free (non-parametric)

methods

Page 22: Groupwise comparison of continuous data

wilcox.testwilcox.test(bone$fn.diff, mu = 0, correct = FALSE)

One-sample

Page 23: Groupwise comparison of continuous data

SIGN.testSIGN.test(bone$fn.diff, md = 0)

One-sample BSDA package

Page 24: Groupwise comparison of continuous data

wilcox.testwilcox.test(bone$fn1, bone$fn2, paired = TRUE,

correct = FALSE)

Paired

Page 25: Groupwise comparison of continuous data

wilcox.testwilcox.test(age ~ zyg, data = bone)

Independent two group

comparison

Page 26: Groupwise comparison of continuous data

3+ group comparison

Page 27: Groupwise comparison of continuous data

Read in BETACAR.DAT.txt

Name it vitA

Plasma level of carotene by different formula of beta-carotene

Page 28: Groupwise comparison of continuous data

anovaanova(lm(Base1lvl ~ factor(Prepar), data = vitA))

Independent 3+ group

comparison

Page 29: Groupwise comparison of continuous data

kruskal.testkruskal.test(Base1lvl ~ factor(Prepar), data = vitA)

Distribution-free

Page 30: Groupwise comparison of continuous data