Groupwise comparison of
 continuous variables in
       2012-10-29 @HSPH
      Kazuki Yoshida, M.D.
        MPH-CLE student


                             FREEDOM
                             TO	
  KNOW
Group Website is at:
http://rpubs.com/kaz_yos/useR_at_HSPH
Previously in this group
n   Introduction

n   Reading Data into R (1)

n   Reading Data into R (2)

n   Descriptive, continuous

n   Descriptive, categorical




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


n   Groupwise comparison of continuous
     variables
Ingredients
         Statistics                          Programming
n   one group vs null hypothesis    n   Creating a new variable

n   two group comparison            n   t.test()

n   multi-group comparison          n   wilcox.test()

n   Distribution-free alternative   n   anova(lm())
     for each
                                     n   kruskal.test()

                                     n   BSDA::SIGN.test()
Open
R Studio
Install and Load
     BSDA
Download comma-separated and Excel




 Put them in folder
BONEDEN.DAT.txt
BETACAR.DAT.txt
        http://www.cengage.com/cgi-wadsworth/course_products_wp.pl?
                 fid=M20bI&product_isbn_issn=9780538733496
Read in BONEDEN.DAT.txt
       Name it bone

 Bone density in twins with
discordant smoking exposure
Indexing: extraction of data from
              data frame

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



       bone[1:15 , 1:12]
    Colon in between
                           Don’t forget comma
age vector within bone data frame
bone$age



Extracted as a vector
Creating a new variable
   new variable              subtraction



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

            alternatively:
       bone <- within(bone, {
          fn.diff <-fn1 - fn2
       })
One-sample t-test



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



          t.test
    t.test(bone$fn1, bone$fn2, paired = TRUE)
Independent
  two group
 comparison


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



 outcome ~ predictor
In the case of t-test

 continuous variable    grouping variable to
   to be compared         separate groups



          age ~ zyg
Variance
comparison
  (F-test)


   var.test
      var.test(age ~ zyg, data = bone)
t-test with
                                 BSDA package
summary data


 tsum.test
 tsum.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)
Distribution-free
(non-parametric)
    methods
One-sample



 wilcox.test
wilcox.test(bone$fn.diff, mu = 0, correct = FALSE)
One-sample                 BSDA package




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



wilcox.test
wilcox.test(bone$fn1, bone$fn2, paired = TRUE,
               correct = FALSE)
Independent
  two group
 comparison

  wilcox.test
      wilcox.test(age ~ zyg, data = bone)
3+ group
comparison
Read in BETACAR.DAT.txt
            Name it vitA

Plasma level of carotene by different
     formula of beta-carotene
Independent
  3+ group
 comparison


        anova
  anova(lm(Base1lvl ~ factor(Prepar), data = vitA))
Distribution-
    free


   kruskal.test
  kruskal.test(Base1lvl ~ factor(Prepar), data = vitA)
Groupwise comparison of continuous data

Groupwise comparison of continuous data