R for Statistical Computing (Chapter 7) R7.1 Distribution functions of the Z, Student’s t, 2 and F distributions: computation of the p-values To compute the cumulative distribution function of the above distributions at a value x, use the following functions in R. Z: pnorm(x) t : pt(x,df =) 2 : pchisq(x,df =) F1 , 2 : pf(x,df1=1,df2=2) For example, to evaluate the following probabilities 1. P(Z < 2.05) 2. P(t43 < 1.25) 3. P( 152 23.44 ) 4. P( F4, 12 2.33 ) we use the following R commands: > pnorm(2.05) [1] 0.9798 > pt(1.25,df=43) [1] 0.1090 > 1pchisq(23.44,df=15) [1] 0.0752 > pf(2.33,df1=4,df2=12) [1] 0.8848 R7.2 C7_mes data: the matched and unmatched sample t test The data file C7_mes contains 20 observations of results in Mathematics, English and Sciences, with variable names M, E and S, respectively. The path of the file is c:/Stat/C7_mes.txt. We first load the data file into a data frame and call it “ms”. The procedure is: > ms = read.table(“c:/Stat/C7_mes.txt”,header=T) > attach(ms) Now the data frame contains the data of the three variables M, E and S. To compute the mean and the standard deviation of these variables, we do the following: > mean(ms) M E 81.45 74.95 S 81.10 > sd(ms) M E S 7.997 6.065 9.279 For the matched sample t test, we compute the difference and then calculate its mean as standard deviation as follows: >D=SE > mean(D) [1] 6.15 > sd(D) [1] 8.412