SCRIPT TO APPLY ASSIGNMENT 3 FUNCTIONS TO THE SUPPLIED DATA.

Read the function definitions.

> source("http://www.cs.utoronto.ca/~radford/csc120/a3funs.r")

Read the data, and compute the BMD_change variable as the change in BMD from beginning of experiment to end.

> df <- read.table("http://www.cs.utoronto.ca/~radford/csc120/a3data",header=TRUE)
> df$BMD_change <- df$BMD2 - df$BMD1

Specify which variables we want to look at effects for.

> vars <- c("BMD2","BMD_change","headache", "stomachache")

Set the random number seed so that we can reproduce results.

> set.seed(1)

Find effects and p-values for all subjects.

> print_effects_with_pvalues(df,vars)
         BMD2 BMD_change  headache stomachache
effect 10.964     14.732 -0.001828    0.017796
pvalue  0.076      0.000  0.764000    0.000000

Number of subjects: 500 

Find effects and p-values for male subjects.

> print_effects_with_pvalues(df[df$sex=="M",],vars)
            BMD2 BMD_change     headache stomachache
effect -5.394155   7.368258 -0.004020432  0.01495676
pvalue  0.667000   0.097000  0.788000000  0.01800000

Number of subjects: 130 

Find effects and p-values for female subjects.

> print_effects_with_pvalues(df[df$sex=="F",],vars)
           BMD2 BMD_change     headache stomachache
effect 15.27578   17.26616 -0.001304774  0.01882394
pvalue  0.06300    0.00000  0.671000000  0.00000000

Number of subjects: 370 

Find effects and p-values for female subjects less than age 50.

> print_effects_with_pvalues(df[df$sex=="F" & df$age<50,],vars)
            BMD2 BMD_change     headache stomachache
effect -6.355556   5.613675 -0.002598291  0.01426496
pvalue  0.666000   0.232000  0.718000000  0.02900000

Number of subjects: 84 

Find effects and p-values for female subjects age 50 or above.

> print_effects_with_pvalues(df[df$sex=="F" & df$age>=50,],vars)
           BMD2 BMD_change     headache stomachache
effect 22.46714    20.4195 -0.000870403  0.02004441
pvalue  0.01900     0.0000  0.581000000  0.00000000

Number of subjects: 286