R version 2.14.1 (2011-12-22) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) R est un logiciel libre livré sans AUCUNE GARANTIE. Vous pouvez le redistribuer sous certaines conditions. Tapez 'license()' ou 'licence()' pour plus de détails. R est un projet collaboratif avec de nombreux contributeurs. Tapez 'contributors()' pour plus d'information et 'citation()' pour la façon de le citer dans les publications. Tapez 'demo()' pour des démonstrations, 'help()' pour l'aide en ligne ou 'help.start()' pour obtenir l'aide au format HTML. Tapez 'q()' pour quitter R. CWD = /Users/chl/Documents/Tutors/R_biomed_fr/pub > ## adl.r > ## R --no-save < adl.r > adl.log > ## > ## Shows basic R processing wrt. SPSS syntax available in `adl.spss`. > > ## Importation des données, en enlevant les ID et le sexe > library(foreign) > adl <- read.spss("adl.sav", to.data.frame=TRUE)[,-c(1,3)] > > ## On examine les 6 premiers enregistrements > head(adl) group age los diabetic hypertns afib priorstr smoker psd 1 Treatment 67 18 No No No No No No 2 Treatment 75 17 Yes Yes No No No Yes 3 Treatment 66 17 No No No No No No 4 Treatment 67 15 No No No No No No 5 Control 75 21 No No No No Yes No 6 Treatment 74 17 No No No No No No travel cooking 1 Gets out if someone else drives Some cooking but less than normal 2 Gets out in wheelchair Does nothing for meals 3 Gets out in wheelchair Gets food out if prepared by other 4 Home or hospital bound Does nothing for meals 5 Home or hospital bound Gets food out if prepared by other 6 Home or hospital bound Some cooking but less than normal housekpg 1 Occasional dusting of small jobs 2 No longer keeps house 3 Occasional dusting of small jobs 4 As before 5 Never did any 6 No longer keeps house > > ## Répartition par groupe de traitement et diabète > table(adl$group) Control Treatment 46 54 > table(adl$diabetic) No Yes 85 15 > > ## Distribution des âges > summary(adl$age) Min. 1st Qu. Median Mean 3rd Qu. Max. 66.00 69.00 71.50 71.76 74.00 91.00 > library(e1071) # skewness and kurtosis > cat("Asymétrie =", skewness(adl$age), "\t Aplatissement =", + kurtosis(adl$age), "\n") Asymétrie = 1.439285 Aplatissement = 4.335339 > > hist(adl$age, freq=TRUE) > > ## Distribution des âges et durées d'hospitalisation selon le traitement > boxplot(age ~ group, data=adl) > boxplot(los ~ group, data=adl) > with(adl, by(age, group, summary)) group: Control Min. 1st Qu. Median Mean 3rd Qu. Max. 67.0 69.0 73.0 72.2 74.0 81.0 ------------------------------------------------------------ group: Treatment Min. 1st Qu. Median Mean 3rd Qu. Max. 66.00 68.00 70.00 71.39 73.00 91.00 > with(adl, by(los, group, summary)) group: Control Min. 1st Qu. Median Mean 3rd Qu. Max. 13.00 17.00 18.00 17.83 20.00 22.00 ------------------------------------------------------------ group: Treatment Min. 1st Qu. Median Mean 3rd Qu. Max. 12.00 14.00 17.00 16.76 18.00 25.00 > > ## Tri croisé hypertension x group > xtabs(~ group + hypertns, data=adl) hypertns group No Yes Control 33 13 Treatment 34 20 > library(gmodels) # tableau à la SPSS > with(adl, CrossTable(hypertns, group, expected=TRUE, prop.r=FALSE, + prop.t=FALSE, prop.chisq=FALSE)) Cell Contents |-------------------------| | N | | Expected N | | N / Col Total | |-------------------------| Total Observations in Table: 100 | group hypertns | Control | Treatment | Row Total | -------------|-----------|-----------|-----------| No | 33 | 34 | 67 | | 30.820 | 36.180 | | | 0.717 | 0.630 | | -------------|-----------|-----------|-----------| Yes | 13 | 20 | 33 | | 15.180 | 17.820 | | | 0.283 | 0.370 | | -------------|-----------|-----------|-----------| Column Total | 46 | 54 | 100 | | 0.460 | 0.540 | | -------------|-----------|-----------|-----------| Statistics for All Table Factors Pearson's Chi-squared test ------------------------------------------------------------ Chi^2 = 0.8653119 d.f. = 1 p = 0.3522565 Pearson's Chi-squared test with Yates' continuity correction ------------------------------------------------------------ Chi^2 = 0.5138995 d.f. = 1 p = 0.4734556 > > ## Test de Student > t.test(los ~ group, data=adl) # unequal variance (default option) Welch Two Sample t-test data: los by group t = 2.1216, df = 97.549, p-value = 0.0364 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.06890053 2.06475487 sample estimates: mean in group Control mean in group Treatment 17.82609 16.75926 > t.test(los ~ group, data=adl, var.equal=TRUE) Two Sample t-test data: los by group t = 2.0831, df = 98, p-value = 0.03985 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.05051236 2.08314303 sample estimates: mean in group Control mean in group Treatment 17.82609 16.75926 >