The R Project SVN R

Rev

Rev 84897 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 84897 Rev 85145
Line 1... Line 1...
1
 
1
 
2
R Under development (unstable) (2023-07-31 r84793) -- "Unsuffered Consequences"
2
R Under development (unstable) (2023-09-10 r85120) -- "Unsuffered Consequences"
3
Copyright (C) 2023 The R Foundation for Statistical Computing
3
Copyright (C) 2023 The R Foundation for Statistical Computing
4
Platform: x86_64-apple-darwin21.6.0
4
Platform: x86_64-pc-linux-gnu
5
 
5
 
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
6
R is free software and comes with ABSOLUTELY NO WARRANTY.
7
You are welcome to redistribute it under certain conditions.
7
You are welcome to redistribute it under certain conditions.
8
Type 'license()' or 'licence()' for distribution details.
8
Type 'license()' or 'licence()' for distribution details.
9
 
9
 
10
  Natural language support but running in an English locale
-
 
11
 
-
 
12
R is a collaborative project with many contributors.
10
R is a collaborative project with many contributors.
13
Type 'contributors()' for more information and
11
Type 'contributors()' for more information and
14
'citation()' on how to cite R or R packages in publications.
12
'citation()' on how to cite R or R packages in publications.
15
 
13
 
16
Type 'demo()' for some demos, 'help()' for on-line help, or
14
Type 'demo()' for some demos, 'help()' for on-line help, or
Line 1267... Line 1265...
1267
> try( # maxiter=10: store less garbage
1265
> try( # maxiter=10: store less garbage
1268
+         nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = datN,
1266
+         nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = datN,
1269
+             trace=TRUE, control = list(maxiter = 10)) )
1267
+             trace=TRUE, control = list(maxiter = 10)) )
1270
0.01722077  (5.34e+02): par = (0.6168807 -1.783839 2.050204 0.2004597)
1268
0.01722077  (5.34e+02): par = (0.6168807 -1.783839 2.050204 0.2004597)
1271
3.308943e-06 (1.13e+04): par = (0.5798674 -1.784335 2.028943 0.1920502)
1269
3.308943e-06 (1.13e+04): par = (0.5798674 -1.784335 2.028943 0.1920502)
1272
2.571050e-11 (7.68e+06): par = (0.5793882 -1.78778 2.029276 0.1915479)
1270
2.571069e-11 (7.68e+06): par = (0.5793882 -1.78778 2.029276 0.1915479)
1273
1.672513e-23 (5.07e+03): par = (0.5793887 -1.787785 2.029277 0.1915475)
1271
1.669346e-23 (5.53e+03): par = (0.5793887 -1.787785 2.029277 0.1915475)
1274
1.398240e-29 (2.39e+01): par = (0.5793887 -1.787785 2.029277 0.1915475)
1272
2.285755e-29 (1.59e+01): par = (0.5793887 -1.787785 2.029277 0.1915475)
1275
1.346295e-29 (1.19e+01): par = (0.5793887 -1.787785 2.029277 0.1915475)
1273
1.345909e-29 (1.20e+01): par = (0.5793887 -1.787785 2.029277 0.1915475)
1276
1.224935e-29 (9.62e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1274
1.224242e-29 (9.63e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1277
1.224935e-29 (9.62e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1275
1.224242e-29 (9.63e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1278
1.224935e-29 (9.62e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1276
1.224242e-29 (9.63e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1279
1.224935e-29 (9.62e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1277
1.224242e-29 (9.63e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1280
1.224935e-29 (9.62e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1278
1.224242e-29 (9.63e+00): par = (0.5793887 -1.787785 2.029277 0.1915475)
1281
Error in nls(y ~ cbind(exp(-exp(lrc1) * x), exp(-exp(lrc2) * x)), data = xy,  : 
1279
Error in nls(y ~ cbind(exp(-exp(lrc1) * x), exp(-exp(lrc2) * x)), data = xy,  : 
1282
  number of iterations exceeded maximum of 10
1280
  number of iterations exceeded maximum of 10
1283
> ## End(Don't show)
1281
> ## End(Don't show)
1284
> fmX1 <- nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = datN, control = list(scaleOffset=1))
1282
> fmX1 <- nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = datN, control = list(scaleOffset=1))
1285
> fmX  <- nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = datN,
1283
> fmX  <- nls(conc ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = datN,
Line 1288... Line 1286...
1288
  It.   1, fac=           1, eval (no.,total): ( 1,  1): new dev = 3.30894e-06
1286
  It.   1, fac=           1, eval (no.,total): ( 1,  1): new dev = 3.30894e-06
1289
3.308942e-06  (9.08e-04): par = (0.5798674 -1.784335 2.028943 0.1920502)
1287
3.308942e-06  (9.08e-04): par = (0.5798674 -1.784335 2.028943 0.1920502)
1290
  It.   2, fac=           1, eval (no.,total): ( 1,  2): new dev = 2.57108e-11
1288
  It.   2, fac=           1, eval (no.,total): ( 1,  2): new dev = 2.57108e-11
1291
2.571081e-11  (2.53e-06): par = (0.5793882 -1.78778 2.029276 0.1915479)
1289
2.571081e-11  (2.53e-06): par = (0.5793882 -1.78778 2.029276 0.1915479)
1292
  It.   3, fac=           1, eval (no.,total): ( 1,  3): new dev = 1.66926e-23
1290
  It.   3, fac=           1, eval (no.,total): ( 1,  3): new dev = 1.66926e-23
1293
1.669255e-23  (2.04e-12): par = (0.5793887 -1.787785 2.029277 0.1915475)
1291
1.669257e-23  (2.04e-12): par = (0.5793887 -1.787785 2.029277 0.1915475)
1294
1.670549e-23  (1.67e-13): par = (2.029277 0.5793887 0.1915475 -1.787785)
1292
1.670550e-23  (1.67e-13): par = (2.029277 0.5793887 0.1915475 -1.787785)
1295
> all.equal(coef(fm1), coef(fmX1), tolerance=0) # ... rel.diff.: 1.57e-6
1293
> all.equal(coef(fm1), coef(fmX1), tolerance=0) # ... rel.diff.: 1.57e-6
1296
[1] "Mean relative difference: 1.574113e-06"
1294
[1] "Mean relative difference: 1.574118e-06"
1297
> all.equal(coef(fm1), coef(fmX),  tolerance=0) # ... rel.diff.: 1.03e-12
1295
> all.equal(coef(fm1), coef(fmX),  tolerance=0) # ... rel.diff.: 1.03e-12
1298
[1] "Mean relative difference: 1.032123e-12"
1296
[1] "Mean relative difference: 1.032123e-12"
1299
> ## IGNORE_RDIFF_END
1297
> ## IGNORE_RDIFF_END
1300
> stopifnot(all.equal(coef(fm1), coef(fmX1), tolerance = 6e-6),
1298
> stopifnot(all.equal(coef(fm1), coef(fmX1), tolerance = 6e-6),
1301
+           all.equal(coef(fm1), coef(fmX ), tolerance = 1e-11))
1299
+           all.equal(coef(fm1), coef(fmX ), tolerance = 1e-11))
Line 2549... Line 2547...
2549
13 0-39g/day      30+      5        23
2547
13 0-39g/day      30+      5        23
2550
14     40-79      30+      9        20
2548
14     40-79      30+      9        20
2551
15    80-119      30+      7         5
2549
15    80-119      30+      7         5
2552
16      120+      30+     10         3
2550
16      120+      30+     10         3
2553
> 
2551
> 
-
 
2552
> ## "complete cases" vs. "available cases"
-
 
2553
> colSums(is.na(airquality))  # NAs in Ozone but not Temp
-
 
2554
  Ozone Solar.R    Wind    Temp   Month     Day 
-
 
2555
     37       7       0       0       0       0 
-
 
2556
> ## the default is to summarize *complete cases*:
-
 
2557
> aggregate(cbind(Ozone, Temp) ~ Month, data = airquality, FUN = mean)
-
 
2558
  Month    Ozone     Temp
-
 
2559
1     5 23.61538 66.73077
-
 
2560
2     6 29.44444 78.22222
-
 
2561
3     7 59.11538 83.88462
-
 
2562
4     8 59.96154 83.96154
-
 
2563
5     9 31.44828 76.89655
-
 
2564
> ## to handle missing values *per variable*:
-
 
2565
> aggregate(cbind(Ozone, Temp) ~ Month, data = airquality, FUN = mean,
-
 
2566
+           na.action = na.pass, na.rm = TRUE)
-
 
2567
  Month    Ozone     Temp
-
 
2568
1     5 23.61538 65.54839
-
 
2569
2     6 29.44444 79.10000
-
 
2570
3     7 59.11538 83.90323
-
 
2571
4     8 59.96154 83.96774
-
 
2572
5     9 31.44828 76.90000
-
 
2573
> 
2554
> ## Dot notation:
2574
> ## Dot notation:
2555
> aggregate(. ~ Species, data = iris, mean)
2575
> aggregate(. ~ Species, data = iris, mean)
2556
     Species Sepal.Length Sepal.Width Petal.Length Petal.Width
2576
     Species Sepal.Length Sepal.Width Petal.Length Petal.Width
2557
1     setosa        5.006       3.428        1.462       0.246
2577
1     setosa        5.006       3.428        1.462       0.246
2558
2 versicolor        5.936       2.770        4.260       1.326
2578
2 versicolor        5.936       2.770        4.260       1.326
Line 5074... Line 5094...
5074
    r <- V
5094
    r <- V
5075
    r[] <- Is * V * rep(Is, each = p)
5095
    r[] <- Is * V * rep(Is, each = p)
5076
    r[cbind(1L:p, 1L:p)] <- 1
5096
    r[cbind(1L:p, 1L:p)] <- 1
5077
    r
5097
    r
5078
}
5098
}
5079
<bytecode: 0x7fa76c205b90>
5099
<bytecode: 0x561676fcdd38>
5080
<environment: namespace:stats>
5100
<environment: namespace:stats>
5081
> stopifnot(all.equal(Cl, cov2cor(cov(longley))),
5101
> stopifnot(all.equal(Cl, cov2cor(cov(longley))),
5082
+           all.equal(cor(longley, method = "kendall"),
5102
+           all.equal(cor(longley, method = "kendall"),
5083
+             cov2cor(cov(longley, method = "kendall"))))
5103
+             cov2cor(cov(longley, method = "kendall"))))
5084
> 
5104
> 
Line 7722... Line 7742...
7722
> environment(fo)
7742
> environment(fo)
7723
<environment: R_GlobalEnv>
7743
<environment: R_GlobalEnv>
7724
> environment(as.formula("y ~ x"))
7744
> environment(as.formula("y ~ x"))
7725
<environment: R_GlobalEnv>
7745
<environment: R_GlobalEnv>
7726
> environment(as.formula("y ~ x", env = new.env()))
7746
> environment(as.formula("y ~ x", env = new.env()))
7727
<environment: 0x7fa76d5bb548>
7747
<environment: 0x5616794fa910>
7728
> 
7748
> 
7729
> 
7749
> 
7730
> ## Create a formula for a model with a large number of variables:
7750
> ## Create a formula for a model with a large number of variables:
7731
> xnam <- paste0("x", 1:25)
7751
> xnam <- paste0("x", 1:25)
7732
> (fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
7752
> (fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
Line 10528... Line 10548...
10528
> ### ** Examples
10548
> ### ** Examples
10529
> 
10549
> 
10530
> data.class(model.frame(dist ~ speed, data = cars))
10550
> data.class(model.frame(dist ~ speed, data = cars))
10531
[1] "data.frame"
10551
[1] "data.frame"
10532
> 
10552
> 
-
 
10553
> ## using a subset and an extra variable
-
 
10554
> model.frame(dist ~ speed, data = cars, subset = speed < 10, z = log(dist))
-
 
10555
  dist speed       (z)
-
 
10556
1    2     4 0.6931472
-
 
10557
2   10     4 2.3025851
-
 
10558
3    4     7 1.3862944
-
 
10559
4   22     7 3.0910425
-
 
10560
5   16     8 2.7725887
-
 
10561
6   10     9 2.3025851
-
 
10562
> 
10533
> ## get_all_vars(): new var.s are recycled (iff length matches: 50 = 2*25)
10563
> ## get_all_vars(): new var.s are recycled (iff length matches: 50 = 2*25)
10534
> ncars <- get_all_vars(sqrt(dist) ~ I(speed/2), data = cars, newVar = 2:3)
10564
> ncars <- get_all_vars(sqrt(dist) ~ I(speed/2), data = cars, newVar = 2:3)
10535
> stopifnot(is.data.frame(ncars),
10565
> stopifnot(is.data.frame(ncars),
10536
+           identical(cars, ncars[,names(cars)]),
10566
+           identical(cars, ncars[,names(cars)]),
10537
+           ncol(ncars) == ncol(cars) + 1)
10567
+           ncol(ncars) == ncol(cars) + 1)
Line 11266... Line 11296...
11266
Warning in nls(formula = y ~ Const + A * exp(B * x), algorithm = "default",  :
11296
Warning in nls(formula = y ~ Const + A * exp(B * x), algorithm = "default",  :
11267
  No starting values specified for some parameters.
11297
  No starting values specified for some parameters.
11268
Initializing ‘Const’, ‘A’, ‘B’ to '1.'.
11298
Initializing ‘Const’, ‘A’, ‘B’ to '1.'.
11269
Consider specifying 'start' or using a selfStart model
11299
Consider specifying 'start' or using a selfStart model
11270
1017460.306    (4.15e+02): par = (1 1 1)
11300
1017460.306    (4.15e+02): par = (1 1 1)
11271
758164.7503    (2.34e+02): par = (13.42031396 1.961485 0.05947543746)
11301
758164.7503    (2.34e+02): par = (13.42031396 1.961485 0.05947543745)
11272
269506.3539    (3.23e+02): par = (51.75719815 -13.09155956 0.8428607704)
11302
269506.3539    (3.23e+02): par = (51.75719815 -13.09155956 0.8428607704)
11273
68969.21897    (1.03e+02): par = (76.00069849 -1.935226737 1.019085799)
11303
68969.21896    (1.03e+02): par = (76.0006985 -1.93522674 1.019085799)
11274
633.3672232    (1.29e+00): par = (100.3761515 8.624648408 5.104490268)
11304
633.3672231    (1.29e+00): par = (100.3761515 8.624648403 5.104490265)
11275
151.4400219    (9.39e+00): par = (100.6344391 4.913490983 0.2849209569)
11305
151.4400225    (9.39e+00): par = (100.6344391 4.913490981 0.2849209558)
11276
53.08739856    (7.24e+00): par = (100.6830407 6.899303315 0.4637755075)
11306
53.08739902    (7.24e+00): par = (100.6830407 6.899303306 0.4637755073)
11277
1.344478639    (5.97e-01): par = (100.0368306 9.897714142 0.5169294938)
11307
1.344478646    (5.97e-01): par = (100.0368306 9.897714142 0.516929494)
11278
0.9908415909   (1.55e-02): par = (100.0300625 9.9144191 0.5023516843)
11308
0.9908415909   (1.55e-02): par = (100.0300625 9.9144191 0.5023516843)
11279
0.9906046057   (1.84e-05): par = (100.0288724 9.916224018 0.5025207336)
11309
0.9906046057   (1.84e-05): par = (100.0288724 9.916224018 0.5025207337)
11280
0.9906046054   (9.96e-08): par = (100.028875 9.916228366 0.50252165)
11310
0.9906046054   (9.94e-08): par = (100.028875 9.916228366 0.50252165)
11281
0.9906046054   (5.05e-10): par = (100.028875 9.916228388 0.5025216549)
11311
0.9906046054   (5.87e-10): par = (100.028875 9.916228388 0.5025216549)
11282
Nonlinear regression model
11312
Nonlinear regression model
11283
  model: y ~ Const + A * exp(B * x)
11313
  model: y ~ Const + A * exp(B * x)
11284
   data: parent.frame()
11314
   data: parent.frame()
11285
      Const           A           B 
11315
      Const           A           B 
11286
100.0288750   9.9162284   0.5025217 
11316
100.0288750   9.9162284   0.5025217 
Line 12616... Line 12646...
12616
[1] "link-glm"
12646
[1] "link-glm"
12617
> quasi(link = power(1/3))[c("linkfun", "linkinv")]
12647
> quasi(link = power(1/3))[c("linkfun", "linkinv")]
12618
$linkfun
12648
$linkfun
12619
function (mu) 
12649
function (mu) 
12620
mu^lambda
12650
mu^lambda
12621
<bytecode: 0x7fa76744cb40>
12651
<bytecode: 0x561678e87ca8>
12622
<environment: 0x7fa767453608>
12652
<environment: 0x561678eb1468>
12623
 
12653
 
12624
$linkinv
12654
$linkinv
12625
function (eta) 
12655
function (eta) 
12626
pmax(eta^(1/lambda), .Machine$double.eps)
12656
pmax(eta^(1/lambda), .Machine$double.eps)
12627
<bytecode: 0x7fa76744c9f0>
12657
<bytecode: 0x561678e87b20>
12628
<environment: 0x7fa767453608>
12658
<environment: 0x561678eb1468>
12629
 
12659
 
12630
> 
12660
> 
12631
> 
12661
> 
12632
> 
12662
> 
12633
> cleanEx()
12663
> cleanEx()
Line 16081... Line 16111...
16081
> ## IGNORE_RDIFF_BEGIN
16111
> ## IGNORE_RDIFF_BEGIN
16082
> ## End(Don't show)
16112
> ## End(Don't show)
16083
> getInitial(weight ~ mySSlogis(Time, Asym, xmid, scal),
16113
> getInitial(weight ~ mySSlogis(Time, Asym, xmid, scal),
16084
+            data = subset(ChickWeight, Chick == 1))
16114
+            data = subset(ChickWeight, Chick == 1))
16085
     Asym      xmid      scal 
16115
     Asym      xmid      scal 
16086
937.03003  35.22296  11.40521 
16116
937.03011  35.22296  11.40521 
16087
> ## Don't show: 
16117
> ## Don't show: 
16088
> ## IGNORE_RDIFF_END
16118
> ## IGNORE_RDIFF_END
16089
> ## End(Don't show)
16119
> ## End(Don't show)
16090
> 
16120
> 
16091
> # 'first.order.log.model' is a function object defining a first order
16121
> # 'first.order.log.model' is a function object defining a first order
Line 16986... Line 17016...
16986
> 
17016
> 
16987
> ## look at the internal structure:
17017
> ## look at the internal structure:
16988
> unclass(sfun0)
17018
> unclass(sfun0)
16989
function (v) 
17019
function (v) 
16990
.approxfun(x, y, v, method, yleft, yright, f, na.rm)
17020
.approxfun(x, y, v, method, yleft, yright, f, na.rm)
16991
<bytecode: 0x7fa769fc5aa0>
17021
<bytecode: 0x561676b816f0>
16992
<environment: 0x7fa76d7d28e0>
17022
<environment: 0x561678f33130>
16993
attr(,"call")
17023
attr(,"call")
16994
stepfun(1:3, y0, f = 0)
17024
stepfun(1:3, y0, f = 0)
16995
> ls(envir = environment(sfun0))
17025
> ls(envir = environment(sfun0))
16996
[1] "f"      "method" "na.rm"  "x"      "y"      "yleft"  "yright"
17026
[1] "f"      "method" "na.rm"  "x"      "y"      "yleft"  "yright"
16997
> 
17027
> 
Line 17652... Line 17682...
17652
> ### Aliases: t.test t.test.default t.test.formula
17682
> ### Aliases: t.test t.test.default t.test.formula
17653
> ### Keywords: htest
17683
> ### Keywords: htest
17654
> 
17684
> 
17655
> ### ** Examples
17685
> ### ** Examples
17656
> 
17686
> 
17657
> require(graphics)
17687
> ## Two-sample t-test
17658
> 
-
 
17659
> t.test(1:10, y = c(7:20))      # P = .00001855
17688
> t.test(1:10, y = c(7:20))      # P = .00001855
17660
 
17689
 
17661
	Welch Two Sample t-test
17690
	Welch Two Sample t-test
17662
 
17691
 
17663
data:  1:10 and c(7:20)
17692
data:  1:10 and c(7:20)
Line 17681... Line 17710...
17681
sample estimates:
17710
sample estimates:
17682
mean of x mean of y 
17711
mean of x mean of y 
17683
  5.50000  25.93333 
17712
  5.50000  25.93333 
17684
 
17713
 
17685
> 
17714
> 
17686
> ## Classical example: Student's sleep data
-
 
17687
> plot(extra ~ group, data = sleep)
-
 
17688
> ## Traditional interface
17715
> ## Traditional interface
17689
> with(sleep, t.test(extra[group == 1], extra[group == 2]))
17716
> with(mtcars, t.test(mpg[am == 0], mpg[am == 1]))
17690
 
17717
 
17691
	Welch Two Sample t-test
17718
	Welch Two Sample t-test
17692
 
17719
 
17693
data:  extra[group == 1] and extra[group == 2]
17720
data:  mpg[am == 0] and mpg[am == 1]
17694
t = -1.8608, df = 17.776, p-value = 0.07939
17721
t = -3.7671, df = 18.332, p-value = 0.001374
17695
alternative hypothesis: true difference in means is not equal to 0
17722
alternative hypothesis: true difference in means is not equal to 0
17696
95 percent confidence interval:
17723
95 percent confidence interval:
17697
 -3.3654832  0.2054832
17724
 -11.280194  -3.209684
17698
sample estimates:
17725
sample estimates:
17699
mean of x mean of y 
17726
mean of x mean of y 
17700
     0.75      2.33 
17727
 17.14737  24.39231 
17701
 
17728
 
17702
> 
17729
> 
17703
> ## Formula interface
17730
> ## Formula interface
17704
> t.test(extra ~ group, data = sleep)
17731
> t.test(mpg ~ am, data = mtcars)
17705
 
17732
 
17706
	Welch Two Sample t-test
17733
	Welch Two Sample t-test
17707
 
17734
 
17708
data:  extra by group
17735
data:  mpg by am
17709
t = -1.8608, df = 17.776, p-value = 0.07939
17736
t = -3.7671, df = 18.332, p-value = 0.001374
17710
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
17737
alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
17711
95 percent confidence interval:
17738
95 percent confidence interval:
17712
 -3.3654832  0.2054832
17739
 -11.280194  -3.209684
17713
sample estimates:
17740
sample estimates:
17714
mean in group 1 mean in group 2 
17741
mean in group 0 mean in group 1 
17715
           0.75            2.33 
17742
       17.14737        24.39231 
17716
 
17743
 
17717
> 
17744
> 
-
 
17745
> ## One-sample t-test
-
 
17746
> ## Traditional interface
-
 
17747
> t.test(sleep$extra)
-
 
17748
 
-
 
17749
	One Sample t-test
-
 
17750
 
-
 
17751
data:  sleep$extra
-
 
17752
t = 3.413, df = 19, p-value = 0.002918
-
 
17753
alternative hypothesis: true mean is not equal to 0
-
 
17754
95 percent confidence interval:
-
 
17755
 0.5955845 2.4844155
-
 
17756
sample estimates:
-
 
17757
mean of x 
-
 
17758
     1.54 
-
 
17759
 
-
 
17760
> 
17718
> ## Formula interface to one-sample test
17761
> ## Formula interface
17719
> t.test(extra ~ 1, data = sleep)
17762
> t.test(extra ~ 1, data = sleep)
17720
 
17763
 
17721
	One Sample t-test
17764
	One Sample t-test
17722
 
17765
 
17723
data:  extra
17766
data:  extra
Line 17728... Line 17771...
17728
sample estimates:
17771
sample estimates:
17729
mean of x 
17772
mean of x 
17730
     1.54 
17773
     1.54 
17731
 
17774
 
17732
> 
17775
> 
17733
> ## Formula interface to paired test
17776
> ## Paired t-test
17734
> ## The sleep data are actually paired, so could have been in wide format:
17777
> ## The sleep data is actually paired, so could have been in wide format:
17735
> sleep2 <- reshape(sleep, direction = "wide", 
17778
> sleep2 <- reshape(sleep, direction = "wide",
17736
+                   idvar = "ID", timevar = "group")
17779
+                   idvar = "ID", timevar = "group")
-
 
17780
> 
-
 
17781
> ## Traditional interface
-
 
17782
> t.test(sleep2$extra.1, sleep2$extra.2, paired = TRUE)
-
 
17783
 
-
 
17784
	Paired t-test
-
 
17785
 
-
 
17786
data:  sleep2$extra.1 and sleep2$extra.2
-
 
17787
t = -4.0621, df = 9, p-value = 0.002833
-
 
17788
alternative hypothesis: true mean difference is not equal to 0
-
 
17789
95 percent confidence interval:
-
 
17790
 -2.4598858 -0.7001142
-
 
17791
sample estimates:
-
 
17792
mean difference 
-
 
17793
          -1.58 
-
 
17794
 
-
 
17795
> 
-
 
17796
> ## Formula interface
17737
> t.test(Pair(extra.1, extra.2) ~ 1, data = sleep2)
17797
> t.test(Pair(extra.1, extra.2) ~ 1, data = sleep2)
17738
 
17798
 
17739
	Paired t-test
17799
	Paired t-test
17740
 
17800
 
17741
data:  Pair(extra.1, extra.2)
17801
data:  Pair(extra.1, extra.2)
Line 19497... Line 19557...
19497
> ### * <FOOTER>
19557
> ### * <FOOTER>
19498
> ###
19558
> ###
19499
> cleanEx()
19559
> cleanEx()
19500
> options(digits = 7L)
19560
> options(digits = 7L)
19501
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
19561
> base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n")
19502
Time elapsed:  6.593 0.645 7.828 0 0 
19562
Time elapsed:  4.897 0.113 5.009 0 0 
19503
> grDevices::dev.off()
19563
> grDevices::dev.off()
19504
null device 
19564
null device 
19505
          1 
19565
          1 
19506
> ###
19566
> ###
19507
> ### Local variables: ***
19567
> ### Local variables: ***