R version 4.2.3 (2023-03-15 ucrt) -- "Shortstop Beagle" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > e <- rexp(30) > x <- rnorm(30) > hist(x) > hist(x,breaks=8) > y <- rnorm(100) > hist(y) > hist(e) > hist(e,probability=TRUE) > t <- seq(0,5,0.2) > lines(t,dexp(t)) > hist(x,probability=TRUE) > lines(t,dexp(t)) > q <- seq(0,1,0.1) > qe <- quantile(e,q) > qe.elmeleti <- qexp(q) > qe 0% 10% 20% 30% 0.006366025 0.032688550 0.210598279 0.327172176 40% 50% 60% 70% 0.415412967 0.490363730 0.609699558 0.914633173 80% 90% 100% 1.268915147 1.839480758 3.338329546 > qe.elmeleti [1] 0.0000000 0.1053605 0.2231436 0.3566749 [5] 0.5108256 0.6931472 0.9162907 1.2039728 [9] 1.6094379 2.3025851 Inf > qe - qe.elmeleti 0% 10% 20% 0.006366025 -0.072671966 -0.012545272 30% 40% 50% -0.029502768 -0.095412657 -0.202783450 60% 70% 80% -0.306591173 -0.289339631 -0.340522765 90% 100% -0.463104335 -Inf > plot(qe,qe.elmeleti) > abline(0,1) > e2 <- rexp(100) > qe2 <- quantile(e2,q) > plot(qe2,qe.elmeleti) > abline(0,1) > qn.elmeleti <- qnorm(q) > plot(qe2,qn.elmeleti) > abline(0,1) > y <- rnorm(100) * 2 + 3 > mean(y) [1] 2.665655 > var(y) [1] 3.731034 > qy <- quantile(y,q) > plot(qy,qn.elmeleti) > abline(0,1) > abline(3,2,col="blue") > plot(qn.elmeleti,qy) > abline(0,1) > abline(3,2,col="blue") > ?qqplot starting httpd help server ... done > ?qqplot > qqplot(e2,qexp(q)) > qqplot(e2,qexp) Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic > qqplot(e2,qexp(seq(0,1,0.05))) > qqnorm(y) > abline(3,2,col="blue") > qqline(y,col="red") > qqline(y,distribution=exp) > qqplot(e2,qexp(seq(0,1,0.05))) > qqline(y,distribution=exp) > qqplot(e2,qexp(seq(0,1,0.05))) > qqline(e2,distribution=exp) > qqplot(e2,qexp(seq(0,1,0.05))) > qqline(e2,distribution=qexp) > x <- rnorm(30) > y <- rnorm(30) + 3 > mean(x) [1] -0.08588092 > mean(y) [1] 3.095892 > x <- rnorm(30) > y <- rnorm(30) + 3 > mean(x) [1] 0.03593734 > mean(y) [1] 3.055083 > x <- rnorm(30) > y <- rnorm(30) + 3 > mean(x) [1] -0.1406691 > mean(y) [1] 3.139988 > x <- rnorm(30) > y <- rnorm(30) + 3 > mean(x) [1] -0.3526888 > mean(y) [1] 3.123097 > plot(z,dt(z,df=1),type="l") Error in plot(z, dt(z, df = 1), type = "l") : object 'z' not found > z <- seq(-5,5,0.1) > plot(z,dt(z,df=1),type="l") > plot(z,dt(z,df=1),type="l") > lines(z,dt(z,df=5),col="blue") > lines(z,dt(z,df=20),col="red") > lines(z,dt(z,df=Inf),col="green") > plot(z,dt(z,df=1),type="l",ylim=c(0,1)) > lines(z,dt(z,df=5),col="blue") > lines(z,dt(z,df=20),col="red") > lines(z,dt(z,df=Inf),col="green") > plot(z,dt(z,df=1),type="l",ylim=c(0,0.5)) > lines(z,dt(z,df=5),col="blue") > lines(z,dt(z,df=20),col="red") > lines(z,dt(z,df=Inf),col="green") > plot(z,dt(z,df=29),type="l") > z <- seq(-4,4,0.1) > plot(z,dt(z,df=29),type="l") > qt(c(0.05,0.95),df=29) [1] -1.699127 1.699127 > pt(qt(c(0.05,0.95),df=29),df=29) [1] 0.05 0.95 > abline(v=qt(c(0.05,0.95),df=29)) > tt <- t.test(x) > tt One Sample t-test data: x t = -1.9049, df = 29, p-value = 0.06675 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.73135786 0.02598031 sample estimates: mean of x -0.3526888 > tt$stat t -1.904907 > abline(v=tt$stat,col="red") > for (i in 1:20) { + x <- rnorm(30) ; + abline(v=t.test(x)$stat,col="blue") + } > plot(z,dt(z,df=29),type="l") > qt(c(0.05,0.95),df=29) [1] -1.699127 1.699127 > abline(v=qt(c(0.05,0.95),df=29)) > for (i in 1:20) { + x <- rnorm(30) ; + abline(v=t.test(x)$stat,col="blue",lty=2) + } > abline(v=t.test(y)$stat,col="purple") > t.test(y)$stat t 14.6773 > tt One Sample t-test data: x t = -1.9049, df = 29, p-value = 0.06675 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.73135786 0.02598031 sample estimates: mean of x -0.3526888 > abline(v=tt$stat,col="red") > tt One Sample t-test data: x t = -1.9049, df = 29, p-value = 0.06675 alternative hypothesis: true mean is not equal to 0 95 percent confidence interval: -0.73135786 0.02598031 sample estimates: mean of x -0.3526888 > tt$stat t -1.904907 > pt(tt$stat) Error in pt(tt$stat) : argument "df" is missing, with no default > pt(tt$stat,df=29) t 0.03337634 > pt(tt$stat,df=29) t 0.03337634 > 2*pt(tt$stat,df=29) t 0.06675268 > tt$p.value [1] 0.06675268 > y <- rnorm(30) + 3 > t.test(y,mu=3) One Sample t-test data: y t = 0.071018, df = 29, p-value = 0.9439 alternative hypothesis: true mean is not equal to 3 95 percent confidence interval: 2.627463 3.399339 sample estimates: mean of x 3.013401 > t.test(y,mu=2.8) One Sample t-test data: y t = 1.1309, df = 29, p-value = 0.2674 alternative hypothesis: true mean is not equal to 2.8 95 percent confidence interval: 2.627463 3.399339 sample estimates: mean of x 3.013401 > ?t.test > x <- rnorm(20) + 3 > t.test(x,y) Welch Two Sample t-test data: x and y t = -0.24902, df = 46.789, p-value = 0.8044 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -0.5885560 0.4589112 sample estimates: mean of x mean of y 2.948579 3.013401 > z <- y - 1 + rnorm(30) > t.test(y,z,paired=TRUE) Paired t-test data: y and z t = 5.7248, df = 29, p-value = 3.397e-06 alternative hypothesis: true mean difference is not equal to 0 95 percent confidence interval: 0.8067382 1.7035538 sample estimates: mean difference 1.255146 > plot(t,dt(t,df=29),type="l") > abline(v=qt(0.1,df=29)) > t <- seq(-3,3,0.2) > plot(t,dt(t,df=29),type="l") > abline(v=qt(0.1,df=29)) > t.test(z-y,alternative="less") One Sample t-test data: z - y t = -5.7248, df = 29, p-value = 1.698e-06 alternative hypothesis: true mean is less than 0 95 percent confidence interval: -Inf -0.8826197 sample estimates: mean of x -1.255146 > t.test(y,z,alternative="less",paired=TRUE) Paired t-test data: y and z t = 5.7248, df = 29, p-value = 1 alternative hypothesis: true mean difference is less than 0 95 percent confidence interval: -Inf 1.627672 sample estimates: mean difference 1.255146 > t.test(z,y,alternative="less",paired=TRUE) Paired t-test data: z and y t = -5.7248, df = 29, p-value = 1.698e-06 alternative hypothesis: true mean difference is less than 0 95 percent confidence interval: -Inf -0.8826197 sample estimates: mean difference -1.255146 > x <- round(runif(50)) > y <- round(runif(50)) > adat <- data.frame(x=x,y=y) > adat x y 1 1 0 2 0 1 3 1 0 4 0 1 5 0 1 6 0 0 7 0 0 8 0 1 9 1 0 10 0 1 11 1 0 12 0 0 13 1 0 14 0 0 15 0 1 16 1 0 17 0 0 18 0 1 19 1 1 20 0 1 21 0 0 22 0 1 23 0 0 24 0 1 25 0 0 26 1 1 27 1 1 28 0 1 29 1 1 30 1 1 31 1 0 32 1 1 33 0 0 34 1 0 35 0 0 36 1 0 37 1 1 38 0 1 39 1 0 40 0 1 41 1 1 42 1 0 43 0 1 44 1 0 45 1 1 46 1 0 47 1 0 48 1 1 49 0 0 50 1 1 > adat$z <- x+y > adat x y z 1 1 0 1 2 0 1 1 3 1 0 1 4 0 1 1 5 0 1 1 6 0 0 0 7 0 0 0 8 0 1 1 9 1 0 1 10 0 1 1 11 1 0 1 12 0 0 0 13 1 0 1 14 0 0 0 15 0 1 1 16 1 0 1 17 0 0 0 18 0 1 1 19 1 1 2 20 0 1 1 21 0 0 0 22 0 1 1 23 0 0 0 24 0 1 1 25 0 0 0 26 1 1 2 27 1 1 2 28 0 1 1 29 1 1 2 30 1 1 2 31 1 0 1 32 1 1 2 33 0 0 0 34 1 0 1 35 0 0 0 36 1 0 1 37 1 1 2 38 0 1 1 39 1 0 1 40 0 1 1 41 1 1 2 42 1 0 1 43 0 1 1 44 1 0 1 45 1 1 2 46 1 0 1 47 1 0 1 48 1 1 2 49 0 0 0 50 1 1 2 > table(x,y) y x 0 1 0 11 14 1 14 11 > table(x) x 0 1 25 25 > table(y) y 0 1 25 25 > table(x,z) Error in table(x, z) : all arguments must have the same length > z <- adat$z > table(x,z) z x 0 1 2 0 11 14 0 1 0 14 11 > chisq.test(x,z) Pearson's Chi-squared test data: x and z X-squared = 22, df = 2, p-value = 1.67e-05 > chisq.test(x,y) Pearson's Chi-squared test with Yates' continuity correction data: x and y X-squared = 0.32, df = 1, p-value = 0.5716 > chisq.test(table(x,y)) Pearson's Chi-squared test with Yates' continuity correction data: table(x, y) X-squared = 0.32, df = 1, p-value = 0.5716 > a <- rnorm(100) > b <- rnorm(100) > c <- a+b > ?cut > a.int <- cut(a,breaks=2) > a.int [1] (0.03,2.5] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] [5] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] (-2.44,0.03] [9] (-2.44,0.03] (-2.44,0.03] (-2.44,0.03] (-2.44,0.03] [13] (0.03,2.5] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] [17] (0.03,2.5] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] [21] (0.03,2.5] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] [25] (-2.44,0.03] (-2.44,0.03] (-2.44,0.03] (-2.44,0.03] [29] (0.03,2.5] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [33] (0.03,2.5] (-2.44,0.03] (0.03,2.5] (0.03,2.5] [37] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] (-2.44,0.03] [41] (-2.44,0.03] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [45] (-2.44,0.03] (-2.44,0.03] (0.03,2.5] (0.03,2.5] [49] (-2.44,0.03] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] [53] (0.03,2.5] (0.03,2.5] (-2.44,0.03] (0.03,2.5] [57] (-2.44,0.03] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [61] (-2.44,0.03] (-2.44,0.03] (0.03,2.5] (-2.44,0.03] [65] (0.03,2.5] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [69] (0.03,2.5] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [73] (0.03,2.5] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [77] (-2.44,0.03] (-2.44,0.03] (0.03,2.5] (-2.44,0.03] [81] (-2.44,0.03] (0.03,2.5] (0.03,2.5] (-2.44,0.03] [85] (-2.44,0.03] (-2.44,0.03] (0.03,2.5] (0.03,2.5] [89] (-2.44,0.03] (0.03,2.5] (-2.44,0.03] (-2.44,0.03] [93] (-2.44,0.03] (0.03,2.5] (0.03,2.5] (0.03,2.5] [97] (-2.44,0.03] (0.03,2.5] (0.03,2.5] (-2.44,0.03] Levels: (-2.44,0.03] (0.03,2.5] > table(a.int) a.int (-2.44,0.03] (0.03,2.5] 53 47 > b.int <- cut(b,breaks=seq(-2,2,1)) > b.int [1] (0,1] (-2,-1] (-1,0] (-2,-1] (0,1] (-1,0] (0,1] [8] (-1,0] (-1,0] (0,1] (-1,0] (-2,-1] (-2,-1] [15] (-1,0] (-2,-1] (-1,0] (-1,0] (1,2] (-2,-1] [22] (0,1] (1,2] (-1,0] (1,2] (0,1] (-2,-1] (1,2] [29] (-1,0] (-1,0] (-1,0] (1,2] (-1,0] (0,1] (1,2] [36] (1,2] (1,2] (1,2] (-2,-1] (0,1] (-2,-1] (0,1] [43] (0,1] (1,2] (-2,-1] (-2,-1] (1,2] (0,1] (1,2] [50] (0,1] (1,2] (1,2] (0,1] (0,1] (1,2] (-2,-1] [57] (0,1] (-1,0] (1,2] (-2,-1] (1,2] (-2,-1] (0,1] [64] (0,1] (0,1] (-1,0] (-2,-1] (0,1] (-1,0] (-2,-1] [71] (-2,-1] (0,1] (0,1] (0,1] (0,1] (0,1] (-2,-1] [78] (-2,-1] (0,1] (-1,0] (-1,0] (0,1] (-2,-1] (1,2] [85] (-2,-1] (0,1] (0,1] (-1,0] (-1,0] (1,2] (-1,0] [92] (-2,-1] (-1,0] (-1,0] (-1,0] (-2,-1] (-1,0] (-1,0] [99] (-1,0] (-1,0] Levels: (-2,-1] (-1,0] (0,1] (1,2] > table(b.int) b.int (-2,-1] (-1,0] (0,1] (1,2] 23 28 28 19 > sum(table(b.int)) [1] 98 > range(c) [1] -3.407855 4.404248 > min(c) ; max(c) [1] -3.407855 [1] 4.404248 > seq(-4,5,length=3) [1] -4.0 0.5 5.0 > seq(-4,5,length=4) [1] -4 -1 2 5 > c.int <- cut(c,seq(-4,5,length=4)) > c.int [1] (2,5] (-4,-1] (-1,2] (-4,-1] (2,5] (-4,-1] (-1,2] [8] (-1,2] (-4,-1] (-4,-1] (-1,2] (-4,-1] (-1,2] (-1,2] [15] (-4,-1] (-4,-1] (-1,2] (-1,2] (-4,-1] (-1,2] (-1,2] [22] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-4,-1] (-1,2] [29] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (2,5] [36] (-1,2] (-1,2] (-1,2] (-4,-1] (-1,2] (-4,-1] (-1,2] [43] (-1,2] (-1,2] (-4,-1] (-4,-1] (2,5] (-1,2] (-1,2] [50] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] [57] (-1,2] (-1,2] (-1,2] (-4,-1] (-1,2] (-4,-1] (-1,2] [64] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] [71] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-4,-1] [78] (-4,-1] (-1,2] (-4,-1] (-1,2] (-1,2] (-1,2] (-1,2] [85] (-4,-1] (-1,2] (-1,2] (-1,2] (-1,2] (-1,2] (-4,-1] [92] (-4,-1] (-1,2] (-1,2] (-1,2] (-1,2] (-4,-1] (-1,2] [99] (-1,2] (-4,-1] Levels: (-4,-1] (-1,2] (2,5] > chisq.test(a.int,b.int) Pearson's Chi-squared test data: a.int and b.int X-squared = 4.0466, df = 3, p-value = 0.2565 > chisq.test(a.int,c.int) Pearson's Chi-squared test data: a.int and c.int X-squared = 25.9, df = 2, p-value = 2.376e-06 Warning message: In chisq.test(a.int, c.int) : Chi-squared approximation may be incorrect > table(a.int,c.int) c.int a.int (-4,-1] (-1,2] (2,5] (-2.44,0.03] 23 30 0 (0.03,2.5] 1 42 4 > table(a.int,b.int) b.int a.int (-2,-1] (-1,0] (0,1] (1,2] (-2.44,0.03] 13 15 11 13 (0.03,2.5] 10 13 17 6 >