/
datasets-Ex.Rout.save
3470 lines (3249 loc) · 107 KB
/
datasets-Ex.Rout.save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
R version 3.3.1 RC (2016-06-14 r70774) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (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.
Natural language support but running in an English locale
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.
> pkgname <- "datasets"
> source(file.path(R.home("share"), "R", "examples-header.R"))
> options(warn = 1)
> library('datasets')
>
> base::assign(".oldSearch", base::search(), pos = 'CheckExEnv')
> cleanEx()
> nameEx("AirPassengers")
> ### * AirPassengers
>
> flush(stderr()); flush(stdout())
>
> ### Name: AirPassengers
> ### Title: Monthly Airline Passenger Numbers 1949-1960
> ### Aliases: AirPassengers
> ### Keywords: datasets
>
> ### ** Examples
>
> ## Not run:
> ##D ## These are quite slow and so not run by example(AirPassengers)
> ##D
> ##D ## The classic 'airline model', by full ML
> ##D (fit <- arima(log10(AirPassengers), c(0, 1, 1),
> ##D seasonal = list(order = c(0, 1, 1), period = 12)))
> ##D update(fit, method = "CSS")
> ##D update(fit, x = window(log10(AirPassengers), start = 1954))
> ##D pred <- predict(fit, n.ahead = 24)
> ##D tl <- pred$pred - 1.96 * pred$se
> ##D tu <- pred$pred + 1.96 * pred$se
> ##D ts.plot(AirPassengers, 10^tl, 10^tu, log = "y", lty = c(1, 2, 2))
> ##D
> ##D ## full ML fit is the same if the series is reversed, CSS fit is not
> ##D ap0 <- rev(log10(AirPassengers))
> ##D attributes(ap0) <- attributes(AirPassengers)
> ##D arima(ap0, c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12))
> ##D arima(ap0, c(0, 1, 1), seasonal = list(order = c(0, 1, 1), period = 12),
> ##D method = "CSS")
> ##D
> ##D ## Structural Time Series
> ##D ap <- log10(AirPassengers) - 2
> ##D (fit <- StructTS(ap, type = "BSM"))
> ##D par(mfrow = c(1, 2))
> ##D plot(cbind(ap, fitted(fit)), plot.type = "single")
> ##D plot(cbind(ap, tsSmooth(fit)), plot.type = "single")
> ## End(Not run)
>
>
> cleanEx()
> nameEx("BOD")
> ### * BOD
>
> flush(stderr()); flush(stdout())
>
> ### Name: BOD
> ### Title: Biochemical Oxygen Demand
> ### Aliases: BOD
> ### Keywords: datasets
>
> ### ** Examples
>
> ## Don't show:
> options(show.nls.convergence=FALSE)
> old <- options(digits = 5)
> ## End(Don't show)
> require(stats)
> # simplest form of fitting a first-order model to these data
> fm1 <- nls(demand ~ A*(1-exp(-exp(lrc)*Time)), data = BOD,
+ start = c(A = 20, lrc = log(.35)))
> coef(fm1)
A lrc
19.14258 -0.63282
> fm1
Nonlinear regression model
model: demand ~ A * (1 - exp(-exp(lrc) * Time))
data: BOD
A lrc
19.143 -0.633
residual sum-of-squares: 26
> # using the plinear algorithm
> fm2 <- nls(demand ~ (1-exp(-exp(lrc)*Time)), data = BOD,
+ start = c(lrc = log(.35)), algorithm = "plinear", trace = TRUE)
32.946 : -1.0498 22.1260
25.992 : -0.62572 19.10319
25.99 : -0.6327 19.1419
25.99 : -0.63282 19.14256
> # using a self-starting model
> fm3 <- nls(demand ~ SSasympOrig(Time, A, lrc), data = BOD)
> summary(fm3)
Formula: demand ~ SSasympOrig(Time, A, lrc)
Parameters:
Estimate Std. Error t value Pr(>|t|)
A 19.143 2.496 7.67 0.0016 **
lrc -0.633 0.382 -1.65 0.1733
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.55 on 4 degrees of freedom
> ## Don't show:
> options(old)
> ## End(Don't show)
>
>
>
> cleanEx()
> nameEx("ChickWeight")
> ### * ChickWeight
>
> flush(stderr()); flush(stdout())
>
> ### Name: ChickWeight
> ### Title: Weight versus age of chicks on different diets
> ### Aliases: ChickWeight
> ### Keywords: datasets
>
> ### ** Examples
>
>
> cleanEx()
> nameEx("DNase")
> ### * DNase
>
> flush(stderr()); flush(stdout())
>
> ### Name: DNase
> ### Title: Elisa assay of DNase
> ### Aliases: DNase
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> ## Don't show:
> options(show.nls.convergence=FALSE)
> ## End(Don't show)
> coplot(density ~ conc | Run, data = DNase,
+ show.given = FALSE, type = "b")
> coplot(density ~ log(conc) | Run, data = DNase,
+ show.given = FALSE, type = "b")
> ## fit a representative run
> fm1 <- nls(density ~ SSlogis( log(conc), Asym, xmid, scal ),
+ data = DNase, subset = Run == 1)
> ## compare with a four-parameter logistic
> fm2 <- nls(density ~ SSfpl( log(conc), A, B, xmid, scal ),
+ data = DNase, subset = Run == 1)
> summary(fm2)
Formula: density ~ SSfpl(log(conc), A, B, xmid, scal)
Parameters:
Estimate Std. Error t value Pr(>|t|)
A -0.007897 0.017200 -0.459 0.654
B 2.377239 0.109516 21.707 5.35e-11 ***
xmid 1.507403 0.102080 14.767 4.65e-09 ***
scal 1.062579 0.056996 18.643 3.16e-10 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.01981 on 12 degrees of freedom
> anova(fm1, fm2)
Analysis of Variance Table
Model 1: density ~ SSlogis(log(conc), Asym, xmid, scal)
Model 2: density ~ SSfpl(log(conc), A, B, xmid, scal)
Res.Df Res.Sum Sq Df Sum Sq F value Pr(>F)
1 13 0.0047896
2 12 0.0047073 1 8.2314e-05 0.2098 0.6551
>
>
>
> cleanEx()
> nameEx("Formaldehyde")
> ### * Formaldehyde
>
> flush(stderr()); flush(stdout())
>
> ### Name: Formaldehyde
> ### Title: Determination of Formaldehyde
> ### Aliases: Formaldehyde
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> plot(optden ~ carb, data = Formaldehyde,
+ xlab = "Carbohydrate (ml)", ylab = "Optical Density",
+ main = "Formaldehyde data", col = 4, las = 1)
> abline(fm1 <- lm(optden ~ carb, data = Formaldehyde))
> summary(fm1)
Call:
lm(formula = optden ~ carb, data = Formaldehyde)
Residuals:
1 2 3 4 5 6
-0.006714 0.001029 0.002771 0.007143 0.007514 -0.011743
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.005086 0.007834 0.649 0.552
carb 0.876286 0.013535 64.744 3.41e-07 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.008649 on 4 degrees of freedom
Multiple R-squared: 0.999, Adjusted R-squared: 0.9988
F-statistic: 4192 on 1 and 4 DF, p-value: 3.409e-07
> opar <- par(mfrow = c(2, 2), oma = c(0, 0, 1.1, 0))
> plot(fm1)
> par(opar)
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("HairEyeColor")
> ### * HairEyeColor
>
> flush(stderr()); flush(stdout())
>
> ### Name: HairEyeColor
> ### Title: Hair and Eye Color of Statistics Students
> ### Aliases: HairEyeColor
> ### Keywords: datasets
>
> ### ** Examples
>
> require(graphics)
> ## Full mosaic
> mosaicplot(HairEyeColor)
> ## Aggregate over sex (as in Snee's original data)
> x <- apply(HairEyeColor, c(1, 2), sum)
> x
Eye
Hair Brown Blue Hazel Green
Black 68 20 15 5
Brown 119 84 54 29
Red 26 17 14 14
Blond 7 94 10 16
> mosaicplot(x, main = "Relation between hair and eye color")
>
>
>
> cleanEx()
> nameEx("Harman23.cor")
> ### * Harman23.cor
>
> flush(stderr()); flush(stdout())
>
> ### Name: Harman23.cor
> ### Title: Harman Example 2.3
> ### Aliases: Harman23.cor
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats)
> (Harman23.FA <- factanal(factors = 1, covmat = Harman23.cor))
Call:
factanal(factors = 1, covmat = Harman23.cor)
Uniquenesses:
height arm.span forearm lower.leg weight
0.158 0.135 0.190 0.187 0.760
bitro.diameter chest.girth chest.width
0.829 0.877 0.801
Loadings:
Factor1
height 0.918
arm.span 0.930
forearm 0.900
lower.leg 0.902
weight 0.490
bitro.diameter 0.413
chest.girth 0.351
chest.width 0.446
Factor1
SS loadings 4.064
Proportion Var 0.508
Test of the hypothesis that 1 factor is sufficient.
The chi square statistic is 611.44 on 20 degrees of freedom.
The p-value is 1.12e-116
> for(factors in 2:4) print(update(Harman23.FA, factors = factors))
Call:
factanal(factors = factors, covmat = Harman23.cor)
Uniquenesses:
height arm.span forearm lower.leg weight
0.170 0.107 0.166 0.199 0.089
bitro.diameter chest.girth chest.width
0.364 0.416 0.537
Loadings:
Factor1 Factor2
height 0.865 0.287
arm.span 0.927 0.181
forearm 0.895 0.179
lower.leg 0.859 0.252
weight 0.233 0.925
bitro.diameter 0.194 0.774
chest.girth 0.134 0.752
chest.width 0.278 0.621
Factor1 Factor2
SS loadings 3.335 2.617
Proportion Var 0.417 0.327
Cumulative Var 0.417 0.744
Test of the hypothesis that 2 factors are sufficient.
The chi square statistic is 75.74 on 13 degrees of freedom.
The p-value is 6.94e-11
Call:
factanal(factors = factors, covmat = Harman23.cor)
Uniquenesses:
height arm.span forearm lower.leg weight
0.127 0.005 0.193 0.157 0.090
bitro.diameter chest.girth chest.width
0.359 0.411 0.490
Loadings:
Factor1 Factor2 Factor3
height 0.886 0.267 -0.130
arm.span 0.937 0.195 0.280
forearm 0.874 0.188
lower.leg 0.877 0.230 -0.145
weight 0.242 0.916 -0.106
bitro.diameter 0.193 0.777
chest.girth 0.137 0.755
chest.width 0.261 0.646 0.159
Factor1 Factor2 Factor3
SS loadings 3.379 2.628 0.162
Proportion Var 0.422 0.329 0.020
Cumulative Var 0.422 0.751 0.771
Test of the hypothesis that 3 factors are sufficient.
The chi square statistic is 22.81 on 7 degrees of freedom.
The p-value is 0.00184
Call:
factanal(factors = factors, covmat = Harman23.cor)
Uniquenesses:
height arm.span forearm lower.leg weight
0.137 0.005 0.191 0.116 0.138
bitro.diameter chest.girth chest.width
0.283 0.178 0.488
Loadings:
Factor1 Factor2 Factor3 Factor4
height 0.879 0.277 -0.115
arm.span 0.937 0.194 0.277
forearm 0.875 0.191
lower.leg 0.887 0.209 0.135 -0.188
weight 0.246 0.882 0.111 -0.109
bitro.diameter 0.187 0.822
chest.girth 0.117 0.729 0.526
chest.width 0.263 0.644 0.141
Factor1 Factor2 Factor3 Factor4
SS loadings 3.382 2.595 0.323 0.165
Proportion Var 0.423 0.324 0.040 0.021
Cumulative Var 0.423 0.747 0.787 0.808
Test of the hypothesis that 4 factors are sufficient.
The chi square statistic is 4.63 on 2 degrees of freedom.
The p-value is 0.0988
>
>
>
> cleanEx()
> nameEx("Harman74.cor")
> ### * Harman74.cor
>
> flush(stderr()); flush(stdout())
>
> ### Name: Harman74.cor
> ### Title: Harman Example 7.4
> ### Aliases: Harman74.cor
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats)
> (Harman74.FA <- factanal(factors = 1, covmat = Harman74.cor))
Call:
factanal(factors = 1, covmat = Harman74.cor)
Uniquenesses:
VisualPerception Cubes PaperFormBoard
0.677 0.866 0.830
Flags GeneralInformation PargraphComprehension
0.768 0.487 0.491
SentenceCompletion WordClassification WordMeaning
0.500 0.514 0.474
Addition Code CountingDots
0.818 0.731 0.824
StraightCurvedCapitals WordRecognition NumberRecognition
0.681 0.833 0.863
FigureRecognition ObjectNumber NumberFigure
0.775 0.812 0.778
FigureWord Deduction NumericalPuzzles
0.816 0.612 0.676
ProblemReasoning SeriesCompletion ArithmeticProblems
0.619 0.524 0.593
Loadings:
Factor1
VisualPerception 0.569
Cubes 0.366
PaperFormBoard 0.412
Flags 0.482
GeneralInformation 0.716
PargraphComprehension 0.713
SentenceCompletion 0.707
WordClassification 0.697
WordMeaning 0.725
Addition 0.426
Code 0.519
CountingDots 0.419
StraightCurvedCapitals 0.565
WordRecognition 0.408
NumberRecognition 0.370
FigureRecognition 0.474
ObjectNumber 0.434
NumberFigure 0.471
FigureWord 0.429
Deduction 0.623
NumericalPuzzles 0.569
ProblemReasoning 0.617
SeriesCompletion 0.690
ArithmeticProblems 0.638
Factor1
SS loadings 7.438
Proportion Var 0.310
Test of the hypothesis that 1 factor is sufficient.
The chi square statistic is 622.91 on 252 degrees of freedom.
The p-value is 2.28e-33
> for(factors in 2:5) print(update(Harman74.FA, factors = factors))
Call:
factanal(factors = factors, covmat = Harman74.cor)
Uniquenesses:
VisualPerception Cubes PaperFormBoard
0.650 0.864 0.844
Flags GeneralInformation PargraphComprehension
0.778 0.375 0.316
SentenceCompletion WordClassification WordMeaning
0.319 0.503 0.258
Addition Code CountingDots
0.670 0.608 0.581
StraightCurvedCapitals WordRecognition NumberRecognition
0.567 0.832 0.850
FigureRecognition ObjectNumber NumberFigure
0.743 0.770 0.625
FigureWord Deduction NumericalPuzzles
0.792 0.629 0.579
ProblemReasoning SeriesCompletion ArithmeticProblems
0.634 0.539 0.553
Loadings:
Factor1 Factor2
VisualPerception 0.506 0.306
Cubes 0.304 0.209
PaperFormBoard 0.297 0.260
Flags 0.327 0.339
GeneralInformation 0.240 0.753
PargraphComprehension 0.171 0.809
SentenceCompletion 0.163 0.809
WordClassification 0.344 0.615
WordMeaning 0.148 0.849
Addition 0.563 0.115
Code 0.591 0.207
CountingDots 0.647
StraightCurvedCapitals 0.612 0.241
WordRecognition 0.315 0.263
NumberRecognition 0.328 0.205
FigureRecognition 0.457 0.218
ObjectNumber 0.431 0.209
NumberFigure 0.601 0.116
FigureWord 0.399 0.222
Deduction 0.379 0.477
NumericalPuzzles 0.604 0.237
ProblemReasoning 0.390 0.462
SeriesCompletion 0.486 0.474
ArithmeticProblems 0.544 0.389
Factor1 Factor2
SS loadings 4.573 4.548
Proportion Var 0.191 0.190
Cumulative Var 0.191 0.380
Test of the hypothesis that 2 factors are sufficient.
The chi square statistic is 420.24 on 229 degrees of freedom.
The p-value is 2.01e-13
Call:
factanal(factors = factors, covmat = Harman74.cor)
Uniquenesses:
VisualPerception Cubes PaperFormBoard
0.500 0.793 0.662
Flags GeneralInformation PargraphComprehension
0.694 0.352 0.316
SentenceCompletion WordClassification WordMeaning
0.300 0.502 0.256
Addition Code CountingDots
0.200 0.586 0.494
StraightCurvedCapitals WordRecognition NumberRecognition
0.569 0.838 0.848
FigureRecognition ObjectNumber NumberFigure
0.643 0.780 0.635
FigureWord Deduction NumericalPuzzles
0.788 0.590 0.580
ProblemReasoning SeriesCompletion ArithmeticProblems
0.597 0.498 0.500
Loadings:
Factor1 Factor2 Factor3
VisualPerception 0.176 0.656 0.198
Cubes 0.122 0.428
PaperFormBoard 0.145 0.563
Flags 0.239 0.487 0.107
GeneralInformation 0.745 0.191 0.237
PargraphComprehension 0.780 0.249 0.118
SentenceCompletion 0.802 0.175 0.160
WordClassification 0.571 0.327 0.256
WordMeaning 0.821 0.248
Addition 0.162 -0.118 0.871
Code 0.198 0.219 0.572
CountingDots 0.179 0.688
StraightCurvedCapitals 0.190 0.381 0.499
WordRecognition 0.231 0.253 0.210
NumberRecognition 0.158 0.299 0.195
FigureRecognition 0.108 0.557 0.186
ObjectNumber 0.178 0.267 0.342
NumberFigure 0.427 0.424
FigureWord 0.167 0.355 0.240
Deduction 0.392 0.472 0.181
NumericalPuzzles 0.178 0.406 0.473
ProblemReasoning 0.382 0.473 0.182
SeriesCompletion 0.379 0.528 0.283
ArithmeticProblems 0.377 0.226 0.554
Factor1 Factor2 Factor3
SS loadings 3.802 3.488 3.186
Proportion Var 0.158 0.145 0.133
Cumulative Var 0.158 0.304 0.436
Test of the hypothesis that 3 factors are sufficient.
The chi square statistic is 295.59 on 207 degrees of freedom.
The p-value is 5.12e-05
Call:
factanal(factors = factors, covmat = Harman74.cor)
Uniquenesses:
VisualPerception Cubes PaperFormBoard
0.438 0.780 0.644
Flags GeneralInformation PargraphComprehension
0.651 0.352 0.312
SentenceCompletion WordClassification WordMeaning
0.283 0.485 0.257
Addition Code CountingDots
0.240 0.551 0.435
StraightCurvedCapitals WordRecognition NumberRecognition
0.491 0.646 0.696
FigureRecognition ObjectNumber NumberFigure
0.549 0.598 0.593
FigureWord Deduction NumericalPuzzles
0.762 0.592 0.583
ProblemReasoning SeriesCompletion ArithmeticProblems
0.601 0.497 0.500
Loadings:
Factor1 Factor2 Factor3 Factor4
VisualPerception 0.160 0.689 0.187 0.160
Cubes 0.117 0.436
PaperFormBoard 0.137 0.570 0.110
Flags 0.233 0.527
GeneralInformation 0.739 0.185 0.213 0.150
PargraphComprehension 0.767 0.205 0.233
SentenceCompletion 0.806 0.197 0.153
WordClassification 0.569 0.339 0.242 0.132
WordMeaning 0.806 0.201 0.227
Addition 0.167 -0.118 0.831 0.166
Code 0.180 0.120 0.512 0.374
CountingDots 0.210 0.716
StraightCurvedCapitals 0.188 0.438 0.525
WordRecognition 0.197 0.553
NumberRecognition 0.122 0.116 0.520
FigureRecognition 0.408 0.525
ObjectNumber 0.142 0.219 0.574
NumberFigure 0.293 0.336 0.456
FigureWord 0.148 0.239 0.161 0.365
Deduction 0.378 0.402 0.118 0.301
NumericalPuzzles 0.175 0.381 0.438 0.223
ProblemReasoning 0.366 0.399 0.123 0.301
SeriesCompletion 0.369 0.500 0.244 0.239
ArithmeticProblems 0.370 0.158 0.496 0.304
Factor1 Factor2 Factor3 Factor4
SS loadings 3.647 2.872 2.657 2.290
Proportion Var 0.152 0.120 0.111 0.095
Cumulative Var 0.152 0.272 0.382 0.478
Test of the hypothesis that 4 factors are sufficient.
The chi square statistic is 226.68 on 186 degrees of freedom.
The p-value is 0.0224
Call:
factanal(factors = factors, covmat = Harman74.cor)
Uniquenesses:
VisualPerception Cubes PaperFormBoard
0.450 0.781 0.639
Flags GeneralInformation PargraphComprehension
0.649 0.357 0.288
SentenceCompletion WordClassification WordMeaning
0.277 0.485 0.262
Addition Code CountingDots
0.215 0.386 0.444
StraightCurvedCapitals WordRecognition NumberRecognition
0.256 0.639 0.706
FigureRecognition ObjectNumber NumberFigure
0.550 0.614 0.596
FigureWord Deduction NumericalPuzzles
0.764 0.521 0.564
ProblemReasoning SeriesCompletion ArithmeticProblems
0.580 0.442 0.478
Loadings:
Factor1 Factor2 Factor3 Factor4 Factor5
VisualPerception 0.161 0.658 0.136 0.182 0.199
Cubes 0.113 0.435 0.107
PaperFormBoard 0.135 0.562 0.107 0.116
Flags 0.231 0.533
GeneralInformation 0.736 0.188 0.192 0.162
PargraphComprehension 0.775 0.187 0.251 0.113
SentenceCompletion 0.809 0.208 0.136
WordClassification 0.568 0.348 0.223 0.131
WordMeaning 0.800 0.215 0.224
Addition 0.175 -0.100 0.844 0.176
Code 0.185 0.438 0.451 0.426
CountingDots 0.222 0.690 0.101 0.140
StraightCurvedCapitals 0.186 0.425 0.458 0.559
WordRecognition 0.197 0.557
NumberRecognition 0.121 0.130 0.508
FigureRecognition 0.400 0.529
ObjectNumber 0.145 0.208 0.562
NumberFigure 0.306 0.325 0.452
FigureWord 0.147 0.242 0.145 0.364
Deduction 0.370 0.452 0.139 0.287 -0.190
NumericalPuzzles 0.170 0.402 0.439 0.230
ProblemReasoning 0.358 0.423 0.126 0.302
SeriesCompletion 0.360 0.549 0.256 0.223 -0.107
ArithmeticProblems 0.371 0.185 0.502 0.307
Factor1 Factor2 Factor3 Factor4 Factor5
SS loadings 3.632 2.964 2.456 2.345 0.663
Proportion Var 0.151 0.124 0.102 0.098 0.028
Cumulative Var 0.151 0.275 0.377 0.475 0.503
Test of the hypothesis that 5 factors are sufficient.
The chi square statistic is 186.82 on 166 degrees of freedom.
The p-value is 0.128
> Harman74.FA <- factanal(factors = 5, covmat = Harman74.cor,
+ rotation = "promax")
> print(Harman74.FA$loadings, sort = TRUE)
Loadings:
Factor1 Factor2 Factor3 Factor4 Factor5
VisualPerception 0.831 -0.127 0.230
Cubes 0.534
PaperFormBoard 0.736 -0.290 0.136
Flags 0.647 -0.104
SeriesCompletion 0.555 0.126 0.127
GeneralInformation 0.764
PargraphComprehension 0.845 -0.140 0.140
SentenceCompletion 0.872 -0.140
WordClassification 0.277 0.505 0.104
WordMeaning 0.846 -0.108
Addition -0.334 1.012
CountingDots 0.206 -0.200 0.722 0.185
ArithmeticProblems 0.197 0.500 0.139
WordRecognition -0.126 0.127 -0.103 0.657
NumberRecognition 0.568
FigureRecognition 0.399 -0.142 -0.207 0.562
ObjectNumber -0.108 0.107 0.613
StraightCurvedCapitals 0.542 0.247 0.618
Code 0.112 0.288 0.486 0.424
NumberFigure 0.255 -0.230 0.211 0.413
FigureWord 0.187 0.347
Deduction 0.404 0.169 0.117 -0.203
NumericalPuzzles 0.393 0.368
ProblemReasoning 0.381 0.188 0.169
Factor1 Factor2 Factor3 Factor4 Factor5
SS loadings 3.529 3.311 2.367 2.109 0.762
Proportion Var 0.147 0.138 0.099 0.088 0.032
Cumulative Var 0.147 0.285 0.384 0.471 0.503
>
>
>
> cleanEx()
> nameEx("InsectSprays")
> ### * InsectSprays
>
> flush(stderr()); flush(stdout())
>
> ### Name: InsectSprays
> ### Title: Effectiveness of Insect Sprays
> ### Aliases: InsectSprays
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> boxplot(count ~ spray, data = InsectSprays,
+ xlab = "Type of spray", ylab = "Insect count",
+ main = "InsectSprays data", varwidth = TRUE, col = "lightgray")
> fm1 <- aov(count ~ spray, data = InsectSprays)
> summary(fm1)
Df Sum Sq Mean Sq F value Pr(>F)
spray 5 2669 533.8 34.7 <2e-16 ***
Residuals 66 1015 15.4
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> opar <- par(mfrow = c(2, 2), oma = c(0, 0, 1.1, 0))
> plot(fm1)
> fm2 <- aov(sqrt(count) ~ spray, data = InsectSprays)
> summary(fm2)
Df Sum Sq Mean Sq F value Pr(>F)
spray 5 88.44 17.688 44.8 <2e-16 ***
Residuals 66 26.06 0.395
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> plot(fm2)
> par(opar)
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("JohnsonJohnson")
> ### * JohnsonJohnson
>
> flush(stderr()); flush(stdout())
>
> ### Name: JohnsonJohnson
> ### Title: Quarterly Earnings per Johnson & Johnson Share
> ### Aliases: JohnsonJohnson
> ### Keywords: datasets
>
> ### ** Examples
>
>
> cleanEx()
> nameEx("LifeCycleSavings")
> ### * LifeCycleSavings
>
> flush(stderr()); flush(stdout())
>
> ### Name: LifeCycleSavings
> ### Title: Intercountry Life-Cycle Savings Data
> ### Aliases: LifeCycleSavings
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> pairs(LifeCycleSavings, panel = panel.smooth,
+ main = "LifeCycleSavings data")
> fm1 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
> summary(fm1)
Call:
lm(formula = sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
Residuals:
Min 1Q Median 3Q Max
-8.2422 -2.6857 -0.2488 2.4280 9.7509
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 28.5660865 7.3545161 3.884 0.000334 ***
pop15 -0.4611931 0.1446422 -3.189 0.002603 **
pop75 -1.6914977 1.0835989 -1.561 0.125530
dpi -0.0003369 0.0009311 -0.362 0.719173
ddpi 0.4096949 0.1961971 2.088 0.042471 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.803 on 45 degrees of freedom
Multiple R-squared: 0.3385, Adjusted R-squared: 0.2797
F-statistic: 5.756 on 4 and 45 DF, p-value: 0.0007904
>
>
>
> cleanEx()
> nameEx("Loblolly")
> ### * Loblolly
>
> flush(stderr()); flush(stdout())
>
> ### Name: Loblolly
> ### Title: Growth of Loblolly pine trees
> ### Aliases: Loblolly
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> plot(height ~ age, data = Loblolly, subset = Seed == 329,
+ xlab = "Tree age (yr)", las = 1,
+ ylab = "Tree height (ft)",
+ main = "Loblolly data and fitted curve (Seed 329 only)")
> fm1 <- nls(height ~ SSasymp(age, Asym, R0, lrc),
+ data = Loblolly, subset = Seed == 329)
> age <- seq(0, 30, length.out = 101)
> lines(age, predict(fm1, list(age = age)))
>
>
>
> cleanEx()
> nameEx("Nile")
> ### * Nile
>
> flush(stderr()); flush(stdout())
>
> ### Name: Nile
> ### Title: Flow of the River Nile
> ### Aliases: Nile
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> par(mfrow = c(2, 2))
> plot(Nile)
> acf(Nile)
> pacf(Nile)
> ar(Nile) # selects order 2
Call:
ar(x = Nile)
Coefficients:
1 2
0.4081 0.1812
Order selected 2 sigma^2 estimated as 21247
> cpgram(ar(Nile)$resid)
> par(mfrow = c(1, 1))
> arima(Nile, c(2, 0, 0))
Call:
arima(x = Nile, order = c(2, 0, 0))
Coefficients:
ar1 ar2 intercept
0.4096 0.1987 919.8397
s.e. 0.0974 0.0990 35.6410
sigma^2 estimated as 20291: log likelihood = -637.98, aic = 1283.96
>
> ## Now consider missing values, following Durbin & Koopman
> NileNA <- Nile
> NileNA[c(21:40, 61:80)] <- NA
> arima(NileNA, c(2, 0, 0))
Call:
arima(x = NileNA, order = c(2, 0, 0))
Coefficients:
ar1 ar2 intercept
0.3622 0.1678 918.3103
s.e. 0.1273 0.1323 39.5037
sigma^2 estimated as 23676: log likelihood = -387.7, aic = 783.41
> plot(NileNA)
> pred <-
+ predict(arima(window(NileNA, 1871, 1890), c(2, 0, 0)), n.ahead = 20)
> lines(pred$pred, lty = 3, col = "red")
> lines(pred$pred + 2*pred$se, lty = 2, col = "blue")
> lines(pred$pred - 2*pred$se, lty = 2, col = "blue")
> pred <-
+ predict(arima(window(NileNA, 1871, 1930), c(2, 0, 0)), n.ahead = 20)
> lines(pred$pred, lty = 3, col = "red")
> lines(pred$pred + 2*pred$se, lty = 2, col = "blue")
> lines(pred$pred - 2*pred$se, lty = 2, col = "blue")
>
> ## Structural time series models
> par(mfrow = c(3, 1))
> plot(Nile)
> ## local level model
> (fit <- StructTS(Nile, type = "level"))
Call:
StructTS(x = Nile, type = "level")
Variances:
level epsilon
1469 15099
> lines(fitted(fit), lty = 2) # contemporaneous smoothing
> lines(tsSmooth(fit), lty = 2, col = 4) # fixed-interval smoothing
> plot(residuals(fit)); abline(h = 0, lty = 3)
> ## local trend model
> (fit2 <- StructTS(Nile, type = "trend")) ## constant trend fitted
Call:
StructTS(x = Nile, type = "trend")
Variances:
level slope epsilon
1427 0 15047
> pred <- predict(fit, n.ahead = 30)
> ## with 50% confidence interval
> ts.plot(Nile, pred$pred,
+ pred$pred + 0.67*pred$se, pred$pred -0.67*pred$se)
>
> ## Now consider missing values
> plot(NileNA)
> (fit3 <- StructTS(NileNA, type = "level"))
Call:
StructTS(x = NileNA, type = "level")
Variances:
level epsilon
685.8 17899.8
> lines(fitted(fit3), lty = 2)
> lines(tsSmooth(fit3), lty = 3)
> plot(residuals(fit3)); abline(h = 0, lty = 3)
>
>
>
> graphics::par(get("par.postscript", pos = 'CheckExEnv'))
> cleanEx()
> nameEx("Orange")
> ### * Orange
>
> flush(stderr()); flush(stdout())
>
> ### Name: Orange
> ### Title: Growth of Orange Trees
> ### Aliases: Orange
> ### Keywords: datasets
>
> ### ** Examples
>
> require(stats); require(graphics)
> coplot(circumference ~ age | Tree, data = Orange, show.given = FALSE)
> fm1 <- nls(circumference ~ SSlogis(age, Asym, xmid, scal),
+ data = Orange, subset = Tree == 3)
> plot(circumference ~ age, data = Orange, subset = Tree == 3,
+ xlab = "Tree age (days since 1968/12/31)",
+ ylab = "Tree circumference (mm)", las = 1,
+ main = "Orange tree data and fitted model (Tree 3 only)")
> age <- seq(0, 1600, length.out = 101)
> lines(age, predict(fm1, list(age = age)))
>
>
>