-
Notifications
You must be signed in to change notification settings - Fork 3
/
.Rhistory (1)
1381 lines (1381 loc) · 54.9 KB
/
.Rhistory (1)
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
arrows(x0 = 3.5, x1 = 7.5, y0 = 7.5, y1 = 7.5, code = 0, lwd = 2, lty = 2)
text(4.5, 8, labels = expression(paste(Delta,"X")), cex = 1.5)
text(3.2, 5.75, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4, 0.35, expression(Y == beta[0] + beta[1]*X), cex = 2, col = "blue")
library(shape)
Arrows(3.5, 1.0, 3.1, 2.8, lwd = 1.5, col = "blue")
text(2.5, 8,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
points(11.03, 8.674, pch = 20)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,10),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6.03, 6.03), y = c(8.674, 11.03), col = "red", lty = 3, lwd = 2)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,15), ylim = c(0,15),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,15),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6.03, 6.03), y = c(8.674, 11.03), col = "red", lty = 3, lwd = 2)
lines(x = c(6.03, 6.03), y = c(8.674, 11.03), col = "red", lty = 3, lwd = 2)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 3, lwd = 2)
points(6, 10.4, pch = 20)
points(6, 8, pch = 20)
text(7, 4, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 3.5, y0 = 3.5, y1 = 7.5, code = 0, lwd = 2, lty = 2)
arrows(x0 = 1, y0 = 5.9, x1 = 3, y1 = 7.7, code = 0, lwd = 2, lty = 2)
arrows(x0 = 1, y0 = 5.9, x1 = 3, y1 = 3, code = 0, lwd = 2, lty = 2)
arrows(x0 = 1, y0 = 5.9, x1 = 3, y1 = 5.9, code = 0, lwd = 2, lty = 2)
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4, labels = expression(paste(Delta,"X")), cex = 1.5)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.5, 7, expression(Y == beta[0] + beta[1]*X), cex = 2, col = "blue")
text(3.2, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.5, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(2.5, 4.5,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(4.5, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 13, expression(Y == beta[0] + beta[1]*X == 5 + 0.9 * X), cex = 2, col = "blue")
text(2, 13, expression(Y == beta[0] + beta[1]*X = 5 + 0.9 * X), cex = 2, col = "blue")
text(2, 13, expression(Y == beta[0] + beta[1]*X), cex = 2, col = "blue")
text(2, 13, expression(Y == 5 + 0.9*X), cex = 2, col = "blue")
text(2, 14, expression(Y == beta[0] + beta[1]*X =), cex = 2, col = "blue")
text(2, 14, expression(Y == beta[0] + beta[1]*X ==), cex = 2, col = "blue")
text(2, 14, paste(expression(Y == beta[0] + beta[1]*X), " = 5 + 0.9 * X"), cex = 2, col = "blue")
text(2, 14, paste(expression(Y == beta[0] + beta[1]*X), cex = 2, col = "blue")
########make a figure and label it slr#####
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 15, expression(Y == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 11, expression(Y == 5 + 0.9*X), cex = 1.7, col = "blue")
library(shape)
Arrows(3.5, 1.0, 3.1, 2.8, lwd = 1.5, col = "blue")
text(2, 14, expression(Y == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 12, expression(Y == 5 + 0.9*X), cex = 1.7, col = "blue")
########make a figure and label it slr#####
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, expression(Y == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 12.5, expression(Y == 5 + 0.9*X), cex = 1.6, col = "blue")
text(2, 14, expression(E{Y|X} == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 14, expression(E\{Y|X\} == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 14, expression(mu[Y|X] == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
text(2, 14, expression(mu[Y|X] == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 14, expression(mu[Y,X] == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
text(2, 14, expression(mu[Y,X] == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 14, expression(mu[Y]|[X] == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
text(2, 14, expression(mu[YX] == beta[0] + beta[1]*X), cex = 1.7, col = "blue")
########make a figure and label it slr#####
z1 = xyz.tips[, 3],
xlim = c(0, 10),
ylim = c(0, 10),
zlim = c(0, 10),
phi = 35,
theta = 450,
lwd = 2,
d = 3,
bty = "g",
ticktype = "detailed")
bookdown:::serve_book()
install.packages("servr")
bookdown:::serve_book()
servr::daemon_stop("4747113896")
<<<<<<< HEAD
=======
mhGoats <- data.frame(Door1 = c("Car", "Aldebaran", "Casiopeia"),
Door2 = c("Aldebaran", "Car", "Casiopeia"),
Door3 = c("Aldebaran", "Casiopeia", "Car"))
mhGoats
mhGoats <- data.frame(Door1 = c("Car", "Aldebaran", "Casiopeia"),
Door2 = c("Aldebaran", "Car", "Casiopeia"),
Door3 = c( "Casiopeia", "Aldebaran","Car"),
ResultIfSwitch = c("Goat", "Car", "Car"))
mhGoats <- data.frame(Door1 = c("Car", "Aldebaran", "Casiopeia"),
Door2 = c("Aldebaran", "Car", "Casiopeia"),
Door3 = c( "Casiopeia", "Aldebaran","Car"),
ResultIfSwitch = c("Goat", "Car", "Car"))
mhGoats
mhGoats <- data.frame(Door1 = c("Car", "Aldebaran", "Casiopeia"),
Door2 = c("Casiopeia", "Car", "Aldebaran"),
Door3 = c( "Casiopeia", "Aldebaran","Car"),
ResultIfSwitch = c("Goat", "Car", "Car"))
mhGoats
mhGoats <- data.frame(Door1 = c("Car", "Aldebaran", "Casiopeia"),
Door2 = c("Casiopeia", "Car", "Aldebaran"),
Door3 = c("Aldebaran", "Casiopeia", "Car"),
ResultIfSwitch = c("Goat", "Car", "Car"))
mhGoats
mhGoats <- data.frame(Door1 = c("Car", "Goat", "Goat"),
Door2 = c("Goat", "Car", "Goat"),
Door3 = c("Goat", "Goat", "Car"),
ResultIfSwitch = c("Goat", "Car", "Car"))
mhGoats <- data.frame(Door1 = c("Car", "Goat", "Goat"),
Door2 = c("Goat", "Car", "Goat"),
Door3 = c("Goat", "Goat", "Car"),
ResultIfSwitch = c("Goat", "Car", "Car"))
mhGoats
mhGoats
knitr::include_graphics("images/CH2Windows.png")
knitr::include_graphics("images/CH2Windows.png")
knitr::include_graphics("images/CH2Windows.png")
knitr::include_graphics("images/CH2Console.png")
knitr::include_graphics("images/CH2Console2.png")
knitr::include_graphics("images/CH2IncompleteError.png")
knitr::include_graphics("images/CH2Error.png")
knitr::include_graphics("images/CH2RunChunk.png")
knitr::include_graphics("images/CH2RmdSave.png")
```{r BasicFunctions, echo=FALSE}
#two ways to calculate the sum of 1 and 5
1 + 5
sum(c(1,5))
#two ways to calculate the mean of 8, 4, and 6
(8 + 4 + 6) / 3
mean(c(8,4,6))
knitr::include_graphics("images/CH2RmdSave.png")
knitr::include_graphics("images/CH2htmlSave.png")
knitr::include_graphics("images/CH2WD.png")
knitr::include_graphics("images/CH2Plot.png")
knitr::include_graphics("images/CH2Packages.png")
mymatrix <- cbind(myvector, myvector2)
mymatrix
mymatrix <- cbind(myvector, myvector2)
myvector <- c(1,2,3)
myvector
myvector2 <- c("one","two","three")
myvector2
help(c) #help() allows you to search for a description of a given function
mymatrix <- cbind(myvector, myvector2)
mymatrix
help(cbind)
mydataframe <- as.data.frame(cbind(myvector, myvector2))
mydataframe
help(as.data.frame)
knitr::include_graphics("images/CH2Import2.png")
plotPoly <- function(b0, b1, b2, b3, xmin, xmax){ # name function and arguments
x <- seq(from = xmin, to = xmax, length.out = 100) # create x values
y <- b0 + b1 * x + b2 * x^2 + b3 * x^3 # calculate y values
plot(y ~ x, type = "l") # plot the results
}
plotPoly(b0 = 1, b1 = 0.5, b2 = 0.03, b3 = -0.01, xmin = -5, xmax = 10)
plotPoly(b0 = 1, b1 = 0.5, b2 = 0.03, b3 = -0.01, xmin = -10, xmax = 10)
a <- c(1, 2, 3, 4, 5)
b <- c(10, 20, 30, 40, 50)
a + 100
## [1] 101 102 103 104 105
a + b
## [1] 11 22 33 44 55
(a + b) / 10
a <- 1:5
b <- 1:5
ab.sum <- a + b
ab.diff <- a - b
ab.prod <- a * b
ab.sum
## [1] 2 4 6 8 10
ab.diff
## [1] 0 0 0 0 0
ab.prod
mydata <- data.frame(Y1 = c("treatment 1", "treatment 2", "treatment 3"), Y2 = c(35, 23, 30)) # Create data frame with 2 columns and 3 rows
mydata # see the contents of the data frame
str(mydata) # see the structure of the data frame
class(mydata) # see the class of the data frame
library(pander) # we need to install pander first
pander(mydata, caption = "Table showing my data.") #pander() creates a table for the data
clover <- read.csv("Datasets/Lab01clover.txt", header = TRUE) # read in data.
help(clover) # Read about the nature of the data set.
(avg.lnwt <- mean(clover$lnwt)) # obtain the average lnwtance; note the use of $ to select parts of an object and the outer parentheses to display the result.
(med.lnwt <- median(clover$lnwt)) # median or 50th percentile
quantile(clover$lnwt, 0.5) # 50th percentile is the same as the median
(var.lnwt <- var(clover$lnwt)) # variance
(std.lnwt <- sd(clover$lnwt)) # standard deviation
sum(clover$lnwt)/length(clover$lnwt) # manual calculation of average
sum( (clover$lnwt - avg.lnwt) ^ 2 ) / (length(clover$lnwt) - 1)
(rng.lnwt <- range(clover$lnwt)) # output is a vector of lenght 2
min(clover$lnwt) # minimum braking lnwtance
max(clover$lnwt) # maximum braking lnwtance
(cv.lnwt <- std.lnwt / avg.lnwt) # coefficient of variation
```{r ps freqhist, echo = TRUE, include = TRUE}
(sample.size <- length(clover$lnwt))
(nbins <- max(8, (1 + log(sample.size, 2)))) # we round down for bins
clover$bin <- cut(clover$lnwt, breaks = nbins) # create column with bin
(freq.table <- as.data.frame(xtabs( ~clover$bin))) # creates frequency table
pander(freq.table) # format the table a little better
plot(freq.table, xlim = c()) # make histogram "by hand"
hist(clover$lnwt) # by default it uses Sturges rule for bins.
summary(clover$lnwt) # summary of a numeric variable or vector
class(clover$lnwt) # a numeriv vector contains real numbers
summary(clover$bin) # this is a character variable coded as a factor
class(clover$bin)
summary(clover) # gives the summary for all variables
class(summary(clover)) # This is functional programming; nested functions
mode(summary(clover))
str(summary(clover)) # See the inside of an object!!
summary(clover)[1,1] # get the first element of the table
summary(clover)[1,] # get the first row of the summary table
summary(clover)[,1] # get the first column of the summary table
myrange.factor = 1.5 # save number in a named object for later use
boxplot(clover$lnwt, range = myrange.factor)
text(x = 0.70, y = median(clover$lnwt), label = "Median")
boxplot(clover$lnwt, range = myrange.factor)
clover$lnwt
plot(clover$lnwt)
boxplot(clover$lnwt)
boxplot(clover$lnwt, range = 1)
boxplot(clover$lnwt, range = 1)
boxplot(clover$lnwt, range = 1.5)
boxplot(clover$lnwt, range = 1.5)
myrange.factor
boxplot(clover$lnwt, range = myrange.factor)
boxplot(clover$lnwt, range = myrange.factor)
boxplot(clover$lnwt, range = 1.5)
boxplot(clover$lnwt, range = 1.5)
boxplot(clover$lnwt, range = 1.5)
boxplot(clover$lnwt, range = 1.5)
boxplot(clover$lnwt, range = 1.5)
boxplot(clover$lnwt, range = 1.5)
myrange.factor <- 1.5
boxplot(clover$lnwt, range = myrange.factor)
text(x = 0.70, y = median(clover$lnwt), label = "Median")
boxplot(clover$lnwt, range = myrange.factor)
myrange.factor = 1.5 # save number in a named object for later use
boxplot(heifer$Birth_Wt, range = myrange.factor)
myrange.factor <- 1.5
boxplot(clover$lnwt, range = myrange.factor)
text(x = 0.70, y = median(clover$lnwt), label = "Median")
text(x = 0.65, y = quantile(clover$lnwt, 0.75), label = "3rd quartile or 75% quantile")
text(x = 1.30, y = quantile(clover$lnwt, 0.75), label = "Upper Hinge")
text(x = 0.65, y = quantile(clover$lnwt, 0.25), label = "1st quartile or 25% quantile")
text(x = 1.30, y = quantile(clover$lnwt, 0.25), label = "Lower Hinge")
myrange.factor = 0.5
boxplot(clover$lnwt, range = myrange.factor)
text(x = 0.70, y = median(clover$lnwt), label = "Median")
text(x = 0.65, y = quantile(clover$lnwt, 0.75), label = "3rd quartile or 75% quantile")
text(x = 1.30, y = quantile(clover$lnwt, 0.75), label = "Upper Hinge")
text(x = 0.65, y = quantile(clover$lnwt, 0.25), label = "1st quartile or 25% quantile")
text(x = 1.30, y = quantile(clover$lnwt, 0.25), label = "Lower Hinge")
(iqrange <- IQR(clover$lnwt)) # Calculate the interquartile range
(uplimit <- quantile(clover$lnwt, 0.75) + myrange.factor * iqrange)
(rows.where.lt.uplimit <- which(clover$lnwt <= uplimit)) # gives row numbers of those that are less than uplimit
clover$lnwt[rows.where.lt.uplimit] # gives lnwt in those rows
(up.fence <- max(clover$lnwt[rows.where.lt.uplimit])) # gives the value we seek
(outl <- clover$lnwt[clover$lnwt > up.fence]) # We have outliers!
text(x = 0.65, y = up.fence, label = "Upper Fence")
sumry.by.temp
sumry.by.temp <- by(data = clover$lnwt, INDICES = clover$temp, FUN = summary
)
sumry.by.temp
pander(sumry.by.temp)
class(sumry.by.temp)
str(sumry.by.temp)
bookdown:::serve_book()
servr::daemon_stop("4559906504")
pander(freq.table) # format the table a little better
set.seed(1221) # To always make the same random sample.
set.seed(1221) # To always make the same random sample.
smpl <- rchisq(n = 100, df = 2)
smpl
mean(c(smpl, 200))
smpl <- rchisq(n = 100, df = 2)
(avg <- mean(smpl))
mean(c(smpl, 200))
plot(sapply(sort(c(-20:80/10, mean(smpl))), FUN = function(i) sum((smpl - i)^2)) ~
sort(c(-20:80/10, mean(smpl))),
type = "l",
lwd = 4,
col = "chocolate",
ylab = "Sum of squared deviations",
xlab = "Value to calculate deviation to")
arrows(x0 = mean(smpl) , y0 = 1500,
x1 = mean(smpl), y1 = sum((smpl - mean(smpl))^2),
angle = 25, length = 0.2,
lwd = 2)
text(x = mean(smpl) , y = 1900 ,
labels = c("Sum of squared deviations \n is minimized when \n X equals the average"))
median(smpl)
median(c(smpl, 200))
plot(sapply(sort(c(-20:80/10, median(smpl))), FUN = function(i) sum(abs(smpl - i))) ~
sort(c(-20:80/10, median(smpl))),
type = "l",
lwd = 4,
col = "chocolate",
ylab = "Sum of absolute deviations",
xlab = "Value to calculate deviation to")
arrows(x0 = median(smpl) , y0 = 350,
x1 = median(smpl), y1 = sum(abs(smpl - median(smpl))),
angle = 25, length = 0.2,
lwd = 2)
text(x = median(smpl) , y = 400 ,
labels = c("Sum of absolute deviations \n is minimized when \n X equals the median"))
```{r Bimodal, message=FALSE, echo=FALSE, out.width='70%', fig.align='center', fig.cap="Example of bimodal distribution. A single central confidence interval would not be very useful. These data should be explored to find a way to stratify into groups."}
set.seed(1333)
smpl2 <- c(rnorm(n = 50, mean = 10, sd = 1), rnorm(n = 50, mean = 20, sd = 2))
plot(density(smpl2, adjust = 0.5),
type = "l",
lwd = 4,
col = "chocolate",
ylab = "Probability density",
xlab = "Random variable value",
main = "")
var(c(1, 2, 3))
mean(c(1, 2, 3))
hvirus <- expand.grid(marker = c("-M", "+M"), Hanta = c("-H", "+H"))
hvirus
str(cards)
str(S)
ProbH <- 0.17
ProbNoH <- 1 - ProbH
ProbM <- 0.63
ProbNoM <- 1 - ProbM
ProbHM <- 0.05
ProbHNoM <- ProbH - ProbHM
ProbHNoM
ProbNoHM <- ProbM - ProbHM
ProbNoHM
P.H <- 0.17
P.h <- 1 - P.H
P.M <- 0.63
P.m <- 1 - P.M
P.HM <- 0.05
P.Hm <- P.H - P.HM
P.hM <- P.M - P.HM
P.hm <- 1 - P.h - P.Hm - P.hM
hvirus
# Create a data frame with the probabilities for each event
hvirus <- expand.grid(marker = c("m", "M"), Hanta = c("h", "H"))
# Create a data frame with the probabilities for each event
hvirus <- expand.grid(Hanta = c("h", "H"), marker = c("m", "M"))
hvirus
hvirus$probs <- c(P.hm, P.Hm, P.hM, P.HM)
hvirus
P.hm <- 1 - P.HM - P.Hm - P.hM
hvirus$probs <- c(P.hm, P.Hm, P.hM, P.HM)
hvirus
sum(hvirus$probs)
install.packages("prob")
library(prob)
marginal(hvirus, vars = "marker")
marginal(hvirus, vars = "Hanta")
P.H * P.M == P.HM
P.h * P.m == P.hm
hvirus
hv.event <- subset(hvirus, Hanta = "H")
M.event <- subset(hvirus, marker = "M")
Prob(hvirus, given = M.event)
M.event
H.event
# Create events for virus and marker
H.event <- subset(hvirus, Hanta = "H")
H.event
# Create events for virus and marker
H.event <- subset(hvirus, Hanta == "H")
M.event <- subset(hvirus, marker == "M")
H.event
M.event
Prob(hvirus, given = M.event)
H.event
M.event
Prob(H.event, given = M.event)
Prob(!H.event, given = M.event)
m.event <- subset(hvirus, marker == "m")
Prob(H.event, given = m.event)
m.event
h.event <- subset(hvirus, Hanta == "h")
Prob(h.event, given = m.event)
Prob(H.event, given = M.event) + Prob(h.event, given = m.event)
Prob(h.event, given = M.event)
Prob(H.event, given = M.event) + Prob(h.event, given = M.event)
Prob(h.event, given = M.event)
P.H <- 0.30
?pbinom # lower.tail = FALSE, q = 9, size = 30, prob = 0.10
Prob(H) * Prob(M, given = H)/(Prob(H) * Prob(M, given = H) + Prob(h) * Prob(M, given = h))
library(prob)
P.H <- 0.17
P.h <- 1 - P.H
P.M <- 0.63
P.m <- 1 - P.M
P.HM <- 0.05
P.Hm <- P.H - P.HM
P.hM <- P.M - P.HM
P.hm <- 1 - P.HM - P.Hm - P.hM
hvirus$probs <- c(P.hm, P.Hm, P.hM, P.HM)
marginal(hvirus, vars = "marker")
marginal(hvirus, vars = "Hanta")
# Is the product of the marginals equal to the joint probability?
P.H * P.M == P.HM
P.h * P.m == P.hm
# Create events for virus and marker
H <- subset(hvirus, Hanta == "H")
M <- subset(hvirus, marker == "M")
Prob(H, given = M)
h <- subset(hvirus, Hanta == "h")
Prob(h, given = M)
Prob(H, given = M) + Prob(h, given = M)
P.H <- 0.30 # New prior probability
P.H * Prob(M, given = H)/(P.H * Prob(M, given = H) + (1 - P.H) * Prob(M, given = h))
pbinom(q = 9, size = 30, prob = 0.10, lower.tail = FALSE)
pbinom(q = 9, size = 50, prob = 0.20, lower.tail = FALSE)
plot(dbinom, x = 0:50, size = 50, prob = 0.20)
plot(dbinom(x = 0:50, size = 50, prob = 0.20) ~ 0:50)
plot(dbinom(x = 0:50, size = 50, prob = 0.20) ~ c(0:50))
plot(dbinom(x = 0:50, size = 50, prob = 0.20) ~ c(0:50), type = "h")
plot(pbinom(q = 9, size = 60:80, prob = 0.20, lower.tail = FALSE) ~ c(60:80))
plot(pbinom(q = 9, size = 60:80, prob = 0.20, lower.tail = FALSE) ~ c(60:80), type = "v")
plot(pbinom(q = 9, size = 60:80, prob = 0.20, lower.tail = FALSE) ~ c(60:80), type = "S")
c(60:80)[which(pbinom(q = 9, size = 60:80, prob = 0.20, lower.tail = FALSE) >= 0.95)]
# Graphical solution
plot(
pbinom(q = 9,
size = 60:80,
prob = 0.20,
lower.tail = FALSE) ~
c(60:80),
type = "S",
ylab = "P(10 or more seeds germinating)")
rate <- 0.0001 # per foot
lambda <- 1000 * rate # per roll
dpois(q = 0, lambda = lambda)
dpois(x = 0, lambda = lambda)
lambda <- 0.0001 # per foot
s = 1000 # feet per roll
rate <- s * lambda # per roll
dpois(x = 0, lambda = rate)
-log(0.999)
-log(0.99)
-log(0.99)/s
-log(0.95)/s
lambda <- 0.00015 # per foot
s = 1000 # feet per roll
rate <- s * lambda # per roll
dpois(x = 0, lambda = rate)
-log(0.95)/s
-log(0.95)
rate
dpois(x = 0, lambda = 100:1/200)
c(100:1/200)[which(dpois(x = 0, lambda = 100:1/200) <= 0.95)]
c(100:1/200)[which(dpois(x = 0, lambda = 100:1/200) >= 0.95)]
0.050/1000
max(c(100:1/200)[which(dpois(x = 0, lambda = 100:1/200) >= 0.95)])
0.05*100
max(c(100:1/200)[which(dpois(x = 0, lambda = seq(from = 0.05, to = 0.045, by = 0.001)) >= 0.95)])
max(c(100:1/200)[which(dpois(x = 0, lambda = seq(from = 0.05, to = 0.045, by = -0.001)) >= 0.95)])
max(c(100:1/200)[which(dpois(x = 0, lambda = seq(from = 0.05, to = 0.055, by = 0.001)) >= 0.95)])
-log(0.95)/s
max(c(seq(from = 0.05, to = 0.055, by = 0.001))[which(dpois(x = 0, lambda = seq(from = 0.05, to = 0.055, by = 0.001)) >= 0.95)])
max(c(guesses)[which(dpois(x = 0, lambda = guesses) >= 0.95)])
guesses <- seq(from = 0.05, to = 0.055, by = 0.001)
max(c(guesses)[which(dpois(x = 0, lambda = guesses) >= 0.95)])
-log(0.95)/s
max(c(guesses)[which(dpois(x = 0, lambda = guesses) >= 0.95)])
max(c(guesses)[which(dpois(x = 0, lambda = guesses) >= 0.95)])/s
curve(dnorm, from = -3.5, to = 4.5)
curve(dnorm(x, sd = 2), from = -3.5, to = 4.5, add = TRUE, col = "chocolate", lwd = 2)
curve(dnorm, from = -5.5, to = 5.5)
curve(dnorm(x, sd = 2), from = -3.5, to = 4.5, add = TRUE, col = "chocolate", lwd = 2)
curve(dnorm(x, sd = 2), from = -5.5, to = 5.5, add = TRUE, col = "chocolate", lwd = 2)
curve(dnorm(x, mean = 1), from = -5.5, to = 5.5, add = TRUE, col = "skyblue", lwd = 2)
# Mutually exclusive events. Add the separate probabilities.
pnorm(q = 1, mean = 5, sd = sqrt(2))
# Mutually exclusive events. Add the separate probabilities.
pnorm(q = 2, mean = 5, sd = sqrt(2))
pnorm(q = 7, mean = 5, sd = sqrt(2), lower.tail = FALSE)
# Mutually exclusive events. Add the separate probabilities.
left.area <- pnorm(q = 2, mean = 5, sd = sqrt(2))
right.area <- pnorm(q = 7, mean = 5, sd = sqrt(2), lower.tail = FALSE)
left.area + right.area
zTable <- matrix(NA, nrow = 33, ncol = 10)
for (j in 0:9) {
zTable[i, j] <- 1 - pnorm(q = 1/10 + j/100)
}
zTable[i, j+1] <- 1 - pnorm(q = 1/10 + j/100)
zTable[i, j] <- 1 - pnorm(q = 1/10 + (j - 1)/100)
str(zTable)
for (i in 1:33) {
for (j in 1:10) {
print(zTable[i, j])
}
}
for (i in 1:33) {
for (j in 1:10) {
zTable[i, j] <- 1 - pnorm(q = i/10 + (j - 1)/100)
}
}
zTable
row.names(zTable)
row.names(zTable) <- 1:33
row.names(zTable)
colnames(zTable) <- 0:9/10
colnames(zTable)
print(zTable, digits = 7)
kable(zTable, digits = 7)
library(knitr)
kable(zTable, digits = 7)
library(knitr)
library(kableExtra)
kable(zTable, digits = 7, caption = "Right tail areas under the standard normal distribution. For left-tail areas and other calculations consider that the function is symmetric about 0.") %>%
kable_styling(full_width = TRUE, )
zTable <- matrix(NA, nrow = 34, ncol = 10)
for (i in 1:34) {
for (j in 1:10) {
zTable[i, j] <- 1 - pnorm(q = (i - 1)/10 + (j - 1)/100)
}
}
row.names(zTable) <- 1:33
row.names(zTable) <- 0:33/10
colnames(zTable) <- 0:9/10
kable(zTable, digits = 7, caption = "Right tail areas under the standard normal distribution. For left-tail areas and other calculations consider that the function is symmetric about 0.") %>%
kable_styling(full_width = TRUE, )
colnames(zTable) <- 0:9/100
kable(zTable, digits = 7, caption = "Right tail areas under the standard normal distribution. For left-tail areas and other calculations consider that the function is symmetric about 0.") %>%
kable_styling(full_width = TRUE, )
p.values <- c(0.15, 0.10, 0.05, 0.025, 0.01, 0.005)
df <- c(1:30, 16:21*2)
df
tTable <- matrix(nrow = length(df), ncol = length(p.values))
length(p.values)
length(df)
tTable[i, j] <- qt(p = p.values[j], df = df[i])
for (i in 1:36) {
for (j in 1:6) {
tTable[i, j] <- qt(p = p.values[j], df = df[i])
}
}
row.names(tTable) <- p.values
colnames(tTable) <- df
row.names(tTable) <- df
colnames(tTable) <- p.values
kable(tTable, digits = 5, caption = "Values of Student's t with row degrees of freedom that have th eolumn probability under the right tail. For left-tail areas and other calculations consider that the function is symmetric about 0.") %>%
kable_styling(full_width = TRUE, )
install.packages("arrangements")
5 +20+10+15+10+10+30
# Cumulative distribution function for number of 5's in 10 die rolls
(df <- data.frame(k = 0:10, P = pbinom(q = 0:10, size = 10, prob = 1/6)))
plot(df, type = "S", col = "skyblue", lwd = 4)
plot(0:20 + 0.05, dpois(x = 0:20, lambda = 1.5), type = "h", lwd = 4, col = "orange", ylab = "PROBABILITY", xlab = "NUMBER OF PLANTS IN QUADRAT")
points(0:20 - 0.05, dpois(x = 0:20, lambda = 6), type = "h", lwd = 4, col = "black")
# Probability of y crossovers
(df <- data.frame(y = 0:7, P = dpois(x = 0:7, lambda = 0.8)))
plot(df, type = "h", lwd = 4)
plot(df, type = "S", col = "skyblue", lwd = 4)
# Cumulative distribution function for number of crossovers
(df <- data.frame(y = 0:7, P = ppois(q = 0:7, lambda = 0.8)))
plot(df, type = "S", col = "skyblue", lwd = 4)
# Cumulative distribution function for number of 5's in 10 die rolls
(df <- data.frame(k = 0:10, P = pbinom(q = 0:10, size = 10, prob = 1/6)))
plot(df, type = "S", col = "skyblue", lwd = 4)
# Probability of k heads in 5 tosses
(df <- data.frame(k = 0:5, P = dbinom(x = 0:5, size = 5, prob = 0.5)))
plot(df, type = "h", col = "skyblue", lwd = 4)
# Probability of k heads in 5 tosses
(df <- data.frame(k = 0:5, P = pbinom(x = 0:5, size = 5, prob = 0.5)))
# Probability of k heads in 5 tosses
(df <- data.frame(k = 0:5, P = pbinom(q = 0:5, size = 5, prob = 0.5)))
plot(df, type = "h", col = "skyblue", lwd = 4)
plot(df, type = "S", col = "skyblue", lwd = 4)
curve(pnorm(x),
from = -3.5,
to = 3.5,
lwd = 2,
xlab = "Y",
ylab = "")
lwd = 2.5,
xlab = "",
ylab = "")
# Two tails
curve(df(x, df1 = 5, df2 = 15),
from = 0,
to = 6,
lwd = 2.5,
xlab = "",
ylab = "")
abline(h = 0)
# Two tails
curve(df(x, df1 = 5, df2 = 15),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "")
abline(h = 0)
cord.x <- c(qf(0.975, df1 = 5, df2 = 15), seq(qf(0.975, df1 = 5, df2 = 15), 35, 0.01), qf(0.975, df1 = 5, df2 = 15))
cord.y <- c(0, qf(seq(qf(0.975, df1 = 5, df2 = 15), 35, 0.01), df = 15), 0)
cord.y <- c(0, qf(seq(qf(0.975, df1 = 5, df2 = 15), 35, 0.01) df1 = 5, df2 = 15), 0)
cord.y <- c(0, qf(seq(qf(0.975, df1 = 5, df2 = 15), 35, 0.01), df1 = 5, df2 = 15), 0)
cord.x <- c(qf(0.975, df1 = 5, df2 = 15), seq(qf(0.975, df1 = 5, df2 = 15), 6, 0.01), qf(0.975, df1 = 5, df2 = 15))
cord.y <- c(0, qf(seq(qf(0.975, df1 = 5, df2 = 15), 6, 0.01), df1 = 5, df2 = 15), 0)
qf(0.975, df1 = 5, df2 = 15)
seq(qf(0.975, df1 = 5, df2 = 15), 6, 0.01)
cord.y <- c(0, pf(seq(qf(0.975, df1 = 5, df2 = 15), 6, 0.01), df1 = 5, df2 = 15), 0)
polygon(cord.x, cord.y, col = "orange")
qf(0.975, df1 = 5, df2 = 15)
qf(0.95, df1 = 5, df2 = 15)
qf(0.95, df1 = 5, df2 = 15), 5, 0.01)
qf(0.95, df1 = 5, df2 = 15)
seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.01)
qf(0.95, df1 = 5, df2 = 15)
cord.x <- c(qf(0.95, df1 = 5, df2 = 15), seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.02), qf(0.95, df1 = 5, df2 = 15))
cord.y <- c(0, pf(seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.02), df1 = 5, df2 = 15), 0)
polygon(cord.x, cord.y, col = "orange")
pf(seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.02), df1 = 5, df2 = 15)
cord.y <- c(0, df(seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.02), df1 = 5, df2 = 15), 0)
polygon(cord.x, cord.y, col = "orange")
polygon(cord.x, cord.y, col = "skyblue")
curve(df(x, df1 = 5, df2 = 15),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "")
curve(df(x, df1 = 5, df2 = 15),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "")
abline(h = 0)
# Add the shaded area.
cord.x <- c(qf(0.95, df1 = 5, df2 = 15), seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.02), qf(0.95, df1 = 5, df2 = 15))
cord.y <- c(0, df(seq(qf(0.95, df1 = 5, df2 = 15), 5, 0.02), df1 = 5, df2 = 15), 0)
polygon(cord.x, cord.y, col = "skyblue")
curve(df(x, df1 = 5, df2 = 15),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "",
add = TRUE)
### F()
df1 <- 15
df2 <- 15
# Two tails on the right
curve(df(x, df1 = df1, df2 = df2),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "")
abline(h = 0)
cord.x <- c(qf(0.95, df1 = df1, df2 = df2),
seq(qf(0.95, df1 = df1, df2 = df2), 5, 0.02),
qf(0.95, df1 = df1, df2 = df2))
cord.y <- c(0,
df(seq(qf(0.95, df1 = df1, df2 = df2), 5, 0.02),
df1 = df1, df2 = df2), 0)
polygon(cord.x, cord.y, col = "skyblue")
curve(df(x, df1 = df1, df2 = df2),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "",
add = TRUE)
df1 <- 15
df2 <- 15
# Two tails on the right
curve(df(x, df1 = df1, df2 = df2),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "",
ylim = c(-0.05, 0.9))
abline(h = 0)
# Add the shaded area.
cord.x <- c(qf(0.95, df1 = df1, df2 = df2),
seq(qf(0.95, df1 = df1, df2 = df2), 5, 0.02),
qf(0.95, df1 = df1, df2 = df2))
cord.y <- c(0,
df(seq(qf(0.95, df1 = df1, df2 = df2), 5, 0.02),
df1 = df1, df2 = df2), 0)
polygon(cord.x, cord.y, col = "skyblue")
curve(df(x, df1 = df1, df2 = df2),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "",
add = TRUE,
ylim = c(-0.05, 0.9))
qf(0.95, df1 = df1, df2 = df2)
text(x = -0.025, y = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances")
text(x = 0, y = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances")
text(y = -0.025, x = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances")
text(y = -0.03, x = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances")
text(y = -0.04, x = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances")
# Two tails on the right
curve(df(x, df1 = df1, df2 = df2),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "",
ylim = c(-0.05, 0.9))
abline(h = 0)
# Add the shaded area.
cord.x <- c(qf(0.95, df1 = df1, df2 = df2),
seq(qf(0.95, df1 = df1, df2 = df2), 5, 0.02),
qf(0.95, df1 = df1, df2 = df2))
cord.y <- c(0,
df(seq(qf(0.95, df1 = df1, df2 = df2), 5, 0.02),
df1 = df1, df2 = df2), 0)
polygon(cord.x, cord.y, col = "skyblue")
curve(df(x, df1 = df1, df2 = df2),
from = 0,
to = 5,
lwd = 2.5,
xlab = "",
ylab = "",
add = TRUE,
ylim = c(-0.05, 0.9))
text(y = -0.04, x = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances")
text(y = -0.04, x = qf(0.95, df1 = df1, df2 = df2), pos = 4,
labels = "Reject equality of variances", col = "red")
qf(0.95, df1 = df1, df2 = df2)
lines(x = c(2.5, 2.8), y = c(0.03, 0.20))
library(latex2exp)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
text(2, 14, TeX(\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}), cex = 1.7, col = "blue")
text(2, 14, labels =TeX(\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}), cex = 1.7, col = "blue")
plot(TeX(\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}))
text(2, 14, labels =TeX("\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}""), cex = 1.7, col = "blue")
plot(TeX("\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}"))
text(2, 14, labels =TeX("\mu_{Y|X} = \beta_0 + \beta_1 \times{X}"), cex = 1.7, col = "blue")
text(2, 14, labels =TeX("\\mu_{Y|X} = \beta_0 + \beta_1 \times{X}"), cex = 1.7, col = "blue")
text(2, 14, labels =TeX("\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}"), cex = 1.7, col = "blue")
plot(TeX("\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}"), cex = 1.7, col = "blue"))
plot(TeX("\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}"))
plot(TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}$"))
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}$"), cex = 1.7, col = "blue")
########make a figure and label it slr#####
library(latex2exp)
library(shape)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times{X}$"), cex = 1.7, col = "blue")
text(2, 12.5, expression(Y == 5 + 0.9*X), cex = 1.6, col = "blue")
Arrows(3.5, 1.0, 3.1, 2.8, lwd = 1.5, col = "blue")
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 \\times X$"), cex = 1.7, col = "blue")
########make a figure and label it slr#####
library(latex2exp)
library(shape)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 \\ X$"), cex = 1.7, col = "blue")
text(2, 12.5, expression(Y == 5 + 0.9*X), cex = 1.6, col = "blue")
Arrows(3.5, 1.0, 3.1, 2.8, lwd = 1.5, col = "blue")
Arrows(2, 12, 3, 7.75, lwd = 1.5, col = "blue")
Arrows(2, 111.7, 3, 7.85, lwd = 1.5, col = "blue")
Arrows(2, 11.7, 3, 7.85, lwd = 1.5, col = "blue")
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 X$"), cex = 1.7, col = "blue")
text(2, 12.5, expression(Y == 5 + 0.9*X), cex = 1.6, col = "blue")
Arrows(2, 11.7, 3, 7.85, lwd = 1.5, col = "blue")
Arrows(2, 11.7, 3, 7.95, lwd = 1.5, col = "blue")
Arrows(2, 11.7, 3, 8, lwd = 1.5, col = "blue")
########make a figure and label it slr#####
library(latex2exp)
library(shape)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 X$"), cex = 1.7, col = "blue")
text(2, 12.5, expression(Y == 5 + 0.9*X), cex = 1.6, col = "blue")
Arrows(2, 11.7, 3, 8, lwd = 1.5, col = "blue")
Arrows(2.2, 11.7, 3, 8.1, lwd = 1.5, col = "blue")
########make a figure and label it slr#####
library(latex2exp)
library(shape)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = expression(Y[i] - Y == epsilon[i]),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 X$"), cex = 1.7, col = "blue")
text(2, 12.5, expression(Y == 5 + 0.9*X), cex = 1.6, col = "blue")
Arrows(2.2, 11.7, 3, 8.1, lwd = 1.5, col = "blue")
text(2, 12.5, TeX("$\\mu_{Y|X} = 5 + 9 X$"), cex = 1.6, col = "blue")
text(7, 9, labels = TeX("$\\mu_{Y|X} - Y-i = \\epsilon_i$"),cex = 1.5, col = "red")
########make a figure and label it slr#####
library(latex2exp)
<<<<<<< HEAD
library(shape)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1.75,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7, 9, labels = TeX("$\\mu_{Y|X} - Y-i = \\epsilon_i$"),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 X$"), cex = 1.7, col = "blue")
text(2, 12.5, TeX("$\\mu_{Y|X} = 5 + 9 X$"), cex = 1.6, col = "blue")
Arrows(2.2, 11.7, 3, 8.1, lwd = 1.5, col = "blue")
text(7.5, 9, labels = TeX("$\\epsilon_i = \\mu_{Y|X} - Y_i$"),cex = 1.5, col = "red")
########make a figure and label it slr#####
library(latex2exp)
library(shape)
set.seed(400)
x <- 1:1000/100
Y <- 5 + 0.9 * x +rnorm(1000)
plot(x, Y, pch = ".", # xaxt = "n", yaxt = "n",
xlab = "X", ylab = "Y",
xlim = c(0,10), ylim = c(0,17),
bty = "l", cex.lab = 1.5, cex = 1,
main = "Population line and X-Y values")
lines(x = c(6, 6), y = c(8, 10.4), col = "red", lty = 1, lwd = 2)
points(6, 8, pch = 20)
lines(0:10, 5 + 0.9 * 0:10, lwd = 2, col = "blue")
text(7.5, 9, labels = TeX("$\\epsilon_i = \\mu_{Y|X} - Y_i$"),cex = 1.5, col = "red")
arrows(x0 = 0.5, y0 = 5.45, x1 = 4, y1 = 5.45, code = 0, lwd = 2, lty = 2)
arrows(x0 = 4, x1 = 4, y0 = 5.45, y1 = 8.6, code = 0, lwd = 2, lty = 2)
text(2.5, 4.5, labels = expression(paste(Delta,"X")), cex = 1.5)
text(4.3, 7, labels = expression(paste(Delta,"Y")), cex = 1.5)
text(4.2, 4,expression(beta[1] == over(Delta*Y,Delta*X)), cex = 1.5)
text(2, 14, labels =TeX("$\\mu_{Y|X} = \\beta_0 + \\beta_1 X$"), cex = 1.7, col = "blue")
text(2, 12.5, TeX("$\\mu_{Y|X} = 5 + 9 X$"), cex = 1.6, col = "blue")
Arrows(2.2, 11.7, 3, 8.1, lwd = 1.5, col = "blue")
########make a figure and label it slr#####