library("readxl")
red_wine <- read_excel("C:/Users/katie/OneDrive - University of Cincinnati/FS20/First Half/Statistical Methods (BANA 7051)/Wine Project/winequality-red.xlsx")
attach(red_wine)

Suppose the population mean of the variable “density” is μ, do the following inferences:

Within this data set, the population is all of the red wines produced in the north of Portugal. The sample is the 1599 observations, or the 1599 bottles of red wine analyzed. In order to provide estimates and inferences about the population, the sample is used.

(a) Provide an estimate of μ based on the sample;

# Estimate of μ based on the sample
mu_density <- mean(density)
mu_density
## [1] 0.9967467

The estimate of μ based on the sample mean of the variable “density” is 0.9967 (rounded to four decimal places.).

(b) Use the Central Limit Theorem (CLT) to quantify the variability of your estimate;

The Central Limit Theorem states that if X1, X2, …, Xn are random variables drawn from the same population (distribution) with the mean μ and the variance σ², then the average approximately follows N(μ, σ²/n).

# Variance of the sample
print(density)
##    [1] 0.99780 0.99680 0.99700 0.99800 0.99780 0.99780 0.99640 0.99460 0.99680
##   [10] 0.99780 0.99590 0.99780 0.99430 0.99740 0.99860 0.99860 0.99690 0.99680
##   [19] 0.99740 0.99690 0.99680 0.99820 0.99660 0.99680 0.99680 0.99550 0.99620
##   [28] 0.99660 0.99720 0.99640 0.99580 0.99660 0.99660 0.99930 0.99570 0.99860
##   [37] 0.99750 0.99680 0.99400 0.99780 0.99780 0.99760 0.99680 0.99680 0.99620
##   [46] 0.99340 0.99700 0.99690 0.99580 0.99540 0.99710 0.99560 0.99550 0.99700
##   [55] 0.99550 0.99780 0.99710 0.99830 0.99750 0.99620 0.99800 0.99680 0.99680
##   [64] 0.99660 0.99620 0.99620 0.99680 0.99620 0.99690 0.99620 0.99670 0.99620
##   [73] 0.99610 0.99760 0.99840 0.99860 0.99860 0.99660 0.99580 0.99720 0.99580
##   [82] 0.99740 0.99700 0.99690 0.99590 0.99610 0.99720 0.99660 0.99780 0.99780
##   [91] 0.99640 0.99720 0.99720 0.99660 0.99380 0.99320 0.99650 0.99630 0.99670
##  [100] 0.99720 0.99720 0.99590 0.99720 0.99670 0.99600 0.99670 0.99730 0.99690
##  [109] 0.99760 0.99690 0.99640 0.99640 0.99640 0.99880 0.99640 0.99660 0.99780
##  [118] 0.99700 0.99620 0.99590 0.99620 0.99620 0.99800 0.99760 0.99600 0.99840
##  [127] 0.99640 0.99640 0.99620 0.99550 0.99680 0.99370 0.99370 0.99520 0.99590
##  [136] 0.99650 0.99680 0.99720 0.99620 0.99620 0.99650 0.99680 0.99160 0.99540
##  [145] 0.99160 0.99680 0.99440 0.99680 0.99590 0.99750 0.99580 0.99960 0.99500
##  [154] 0.99500 0.99730 0.99730 0.99730 0.99730 0.99690 0.99680 0.99590 0.99650
##  [163] 0.99640 0.99820 0.99810 0.99610 0.99560 0.99560 0.99530 0.99640 0.99720
##  [172] 0.99720 0.99720 0.99610 0.99610 0.99580 0.99610 0.99720 0.99690 0.99690
##  [181] 0.99690 0.99720 0.99720 0.99710 0.99700 0.99710 0.99720 0.99760 0.99680
##  [190] 0.99680 0.99760 0.99740 0.99690 0.99640 0.99640 0.99680 0.99680 0.99810
##  [199] 0.99240 0.99480 0.99695 0.99750 0.99545 0.99610 0.99615 0.99940 0.99940
##  [208] 0.99625 0.99660 0.99800 0.99585 0.99685 0.99800 0.99590 0.99740 0.99740
##  [217] 0.99620 0.99670 0.99570 0.99655 0.99640 0.99570 0.99525 0.99815 0.99745
##  [226] 0.99615 0.99640 0.99840 0.99615 0.99685 0.99270 0.99625 0.99800 0.99685
##  [235] 0.99685 0.99675 0.99675 0.99675 0.99675 0.99685 0.99710 0.99925 0.99565
##  [244] 1.00005 1.00005 0.99830 0.99685 0.99630 0.99615 0.99830 0.99850 0.99720
##  [253] 0.99860 0.99590 0.99720 0.99675 0.99800 0.99680 0.99680 0.99965 0.99625
##  [262] 0.99565 0.99575 0.99630 0.99990 0.99680 1.00025 0.99730 0.99870 0.99960
##  [271] 0.99650 0.99960 0.99935 0.99735 0.99915 0.99650 0.99870 0.99960 0.99760
##  [280] 0.99910 0.99860 0.99720 0.99710 0.99910 1.00015 1.00015 0.99970 0.99670
##  [289] 0.99760 1.00100 0.99760 0.99790 0.99940 0.99640 1.00140 1.00010 0.99810
##  [298] 0.99855 0.99930 0.99845 0.99650 0.99730 0.99940 0.99600 0.99730 0.99980
##  [307] 0.99660 0.99940 0.99940 0.99680 0.99980 0.99600 0.99815 0.99760 0.99645
##  [316] 0.99620 0.99960 0.99865 0.99890 0.99865 0.99890 0.99975 0.99735 0.99900
##  [325] 1.00150 1.00150 0.99780 0.99800 1.00020 0.99810 0.99800 0.99800 0.99730
##  [334] 0.99580 0.99630 0.99920 0.99480 0.99740 1.00080 0.99970 1.00000 0.99720
##  [343] 0.99820 0.99820 1.00060 0.99790 0.99550 0.99860 0.99790 0.99940 1.00040
##  [352] 0.99940 0.99740 1.00180 0.99120 0.99550 1.00010 0.99700 1.00000 1.00100
##  [361] 0.99730 0.99820 0.99920 0.99880 1.00220 0.99790 1.00220 1.00000 0.99980
##  [370] 0.99620 0.99750 0.99670 0.99670 0.99590 1.00140 0.99840 1.00030 0.99620
##  [379] 0.99880 0.99790 0.99740 1.00140 0.99740 0.99740 0.99800 0.99790 0.99810
##  [388] 0.99720 0.99810 0.99820 0.99240 1.00140 0.99800 0.99700 0.99970 1.00040
##  [397] 0.99940 0.99880 0.99880 0.99630 0.99940 0.99490 1.00000 0.99940 0.99740
##  [406] 0.99660 0.99810 0.99960 0.99700 0.99810 0.99870 0.99870 0.99660 0.99860
##  [415] 0.99820 1.00140 0.99700 0.99560 0.99960 0.99760 0.99720 0.99520 0.99550
##  [424] 0.99780 0.99550 0.99520 0.99490 0.99880 0.99780 0.99970 0.99780 0.99740
##  [433] 0.99580 1.00040 0.99960 1.00040 0.99580 0.99860 0.99960 0.99510 0.99870
##  [442] 0.99880 1.00320 0.99630 0.99340 0.99860 0.99960 0.99680 0.99670 0.99940
##  [451] 0.99940 0.99790 0.99680 0.99980 0.99520 0.99880 0.99860 0.99880 0.99980
##  [460] 1.00080 0.99760 0.99820 0.99700 0.99720 0.99870 1.00060 0.99820 0.99470
##  [469] 1.00000 0.99520 0.99960 0.99700 0.99950 0.99710 0.99820 0.99880 0.99800
##  [478] 0.99770 0.99880 0.99840 1.00260 0.99640 0.99860 0.99860 0.99700 0.99760
##  [487] 0.99760 0.99820 1.00020 0.99840 0.99840 0.99520 0.99500 1.00020 0.99520
##  [496] 0.99720 0.99840 0.99660 0.99720 1.00020 0.99840 0.99900 0.99900 0.99760
##  [505] 0.99760 0.99680 0.99760 1.00000 0.99940 0.99860 0.99780 0.99940 0.99800
##  [514] 0.99730 0.99730 1.00100 1.00100 0.99940 0.99720 0.99660 0.99820 0.99800
##  [523] 0.99790 0.99780 0.99760 0.99980 0.99660 0.99620 0.99880 0.99740 0.99900
##  [532] 1.00040 1.00040 0.99560 1.00000 0.99900 0.99740 0.99720 1.00140 0.99960
##  [541] 0.99880 0.99880 0.99660 0.99930 1.00080 0.99820 0.99830 0.99870 0.99940
##  [550] 0.99750 0.99580 0.99800 0.99800 0.99340 1.00315 1.00315 1.00020 1.00315
##  [559] 1.00020 1.00210 0.99940 0.99780 0.99820 0.99710 1.00210 0.99940 0.99910
##  [568] 0.99910 0.99900 0.99460 1.00030 0.99460 0.99780 0.99910 0.99920 0.99930
##  [577] 0.99780 0.99820 0.99820 0.99760 1.00020 1.00020 1.00000 0.99760 1.00020
##  [586] 0.99800 0.99860 0.99670 0.99170 0.99760 0.99870 0.99220 0.99870 1.00040
##  [595] 0.99780 0.99980 0.99940 0.99800 0.99670 1.00000 0.99620 1.00060 0.99750
##  [604] 1.00060 0.99840 0.99840 0.99730 0.99820 1.00260 0.99560 0.99830 1.00060
##  [613] 0.99650 0.99620 0.99690 0.99970 0.99970 0.99820 1.00060 0.99880 0.99760
##  [622] 0.99760 0.99740 0.99740 0.99970 0.99970 0.99880 0.99880 0.99760 0.99640
##  [631] 0.99760 0.99880 0.99640 1.00100 0.99640 0.99540 0.99790 0.99780 0.99640
##  [640] 0.99700 0.99910 0.99920 0.99910 0.99920 0.99910 0.99840 0.99720 0.99670
##  [649] 0.99640 0.99480 0.99860 1.00100 0.99760 0.99760 0.99790 1.00040 0.99860
##  [658] 0.99800 0.99730 0.99700 0.99730 0.99780 0.99720 0.99740 1.00000 0.99810
##  [667] 0.99800 0.99880 0.99660 0.99880 0.99590 0.99680 0.99800 0.99680 0.99840
##  [676] 0.99840 0.99840 0.99790 0.99830 0.99720 1.00040 0.99620 0.99800 0.99700
##  [685] 0.99800 0.99700 0.99700 0.99980 0.99620 0.99760 0.99660 0.99980 0.99790
##  [694] 0.99840 0.99840 0.99210 0.99720 0.99720 1.00010 0.99860 0.99840 0.99720
##  [703] 0.99700 0.99720 0.99800 0.99900 0.99560 0.99660 0.99600 0.99830 0.99850
##  [712] 0.99980 0.99920 0.99760 0.99800 0.99670 0.99760 0.99680 0.99760 0.99760
##  [721] 0.99760 0.99820 0.99680 0.99650 0.99580 0.99760 0.99940 0.99700 0.99700
##  [730] 0.99500 0.99820 0.99940 0.99660 0.99800 0.99870 0.99630 0.99630 1.00020
##  [739] 0.99830 0.99900 0.99650 0.99788 0.99720 1.00024 1.00010 0.99768 0.99780
##  [748] 0.99782 0.99761 0.99768 0.99803 0.99803 0.99785 0.99803 0.99656 0.99525
##  [757] 0.99488 0.99656 0.99656 0.99823 0.99779 0.99738 0.99701 0.99738 0.99888
##  [766] 0.99888 0.99738 0.99938 0.99744 0.99668 0.99744 0.99780 0.99782 0.99730
##  [775] 0.99727 0.99586 0.99612 0.99610 0.99788 0.99745 0.99676 0.99732 0.99814
##  [784] 0.99732 0.99746 0.99820 0.99820 0.99910 0.99910 0.99800 0.99708 0.99818
##  [793] 0.99745 0.99639 0.99531 0.99786 0.99746 0.99526 0.99870 0.99870 0.99641
##  [802] 0.99735 0.99264 0.99710 0.99682 0.99356 0.99386 0.99356 0.99702 0.99693
##  [811] 0.99562 1.00012 0.99818 0.99462 0.99939 0.99818 0.99840 0.99545 0.99632
##  [820] 0.99976 0.99606 0.99154 0.99730 0.99730 0.99682 0.99624 0.99510 0.99624
##  [829] 0.99417 0.99376 0.99632 0.99376 0.99832 0.99836 0.99694 0.99655 0.99064
##  [838] 0.99064 0.99672 0.99647 0.99736 0.99629 0.99708 0.99630 0.99590 0.99689
##  [847] 0.99689 0.99770 0.99689 0.99689 0.99708 0.99708 0.99801 0.99652 0.99652
##  [856] 0.99538 0.99652 0.99594 0.99686 0.99438 0.99746 0.99357 0.99628 0.99746
##  [865] 0.99746 0.99748 0.99438 0.99438 0.99438 0.99578 0.99371 0.99522 0.99576
##  [874] 0.99552 0.99664 0.99614 0.99517 0.99371 0.99787 0.99745 0.99576 0.99533
##  [883] 0.99536 0.99745 0.99787 0.99824 0.99836 0.99577 0.99491 1.00289 0.99576
##  [892] 0.99743 0.99774 0.99743 0.99745 0.99550 0.99444 0.99550 0.99444 0.99892
##  [901] 0.99562 0.99736 0.99736 0.99620 0.99620 0.99800 0.99640 0.99480 0.99528
##  [910] 0.99331 0.99577 0.99901 0.99674 0.99639 0.99331 0.99512 0.99395 0.99824
##  [919] 0.99640 0.99504 0.99786 0.99640 0.99504 0.99824 0.99516 0.99604 0.99786
##  [928] 0.99736 0.99516 0.99468 0.99746 0.99748 0.99710 0.99748 0.99746 0.99543
##  [937] 0.99543 0.99791 0.99356 0.99425 0.99509 0.99484 0.99834 0.99864 0.99498
##  [946] 0.99566 0.99745 0.99408 0.99552 0.99552 0.99552 0.99408 0.99536 0.99458
##  [955] 0.99538 0.99648 0.99568 0.99613 0.99519 0.99735 0.99518 0.99592 0.99654
##  [964] 0.99546 0.99518 0.99554 0.99604 0.99733 0.99430 0.99669 0.99724 0.99724
##  [973] 0.99643 0.99605 0.99658 0.99700 0.99700 0.99801 0.99416 0.99690 0.99774
##  [982] 0.99712 0.99418 0.99774 0.99690 0.99562 0.99470 0.99693 0.99596 0.99556
##  [991] 0.99596 0.99694 0.99554 0.99694 0.99918 0.99697 0.99378 0.99378 0.99554
## [1000] 0.99162 0.99495 0.99676 0.99516 0.99280 0.99603 0.99280 0.99516 0.99516
## [1009] 0.99549 0.99722 0.99354 0.99570 0.99604 0.99635 0.99454 0.99598 0.99486
## [1018] 0.99007 0.99007 0.99636 0.99642 0.99642 0.99584 0.99506 0.99568 0.99822
## [1027] 0.99364 0.99378 0.99586 0.99568 0.99488 0.99514 0.99854 0.99592 0.99739
## [1036] 0.99683 0.99356 0.99672 0.99530 0.99692 0.99756 0.99547 0.99692 0.99859
## [1045] 0.99294 0.99438 0.99612 0.99634 0.99702 0.99704 0.99634 0.99702 0.99258
## [1054] 0.99426 0.99747 0.99747 0.99586 0.99784 0.99710 0.99586 0.99810 0.99462
## [1063] 0.99560 0.99565 0.99418 0.99630 0.99358 0.99572 0.99572 0.99700 0.99498
## [1072] 0.99892 0.99680 0.99720 0.99892 0.99769 0.99534 0.99817 0.99817 0.99316
## [1081] 0.99471 0.99316 0.99685 0.99617 0.99685 0.99529 0.99738 0.99400 0.99735
## [1090] 0.99735 0.99451 0.99546 0.99479 0.99615 0.99655 0.99772 0.99655 0.99666
## [1099] 0.99358 0.99666 0.99392 0.99388 0.99402 0.99388 0.99360 0.99374 0.99376
## [1108] 0.99523 0.99855 0.99820 0.99593 0.99471 0.99396 0.99698 0.99020 0.99572
## [1117] 0.99572 0.99572 0.99252 0.99256 0.99235 0.99352 0.99220 0.99674 0.99557
## [1126] 0.99394 0.99150 0.99379 0.99840 0.99798 0.99770 0.99341 0.99330 0.99684
## [1135] 0.99524 0.99460 0.99774 0.99774 0.99786 0.99764 0.99690 0.99624 0.99354
## [1144] 0.99672 0.99588 0.99672 0.99600 0.99702 0.99526 0.99585 0.99473 0.99352
## [1153] 0.99616 0.99622 0.99544 0.99616 0.99524 0.99240 0.99572 0.99728 0.99676
## [1162] 0.99551 0.99434 0.99692 0.99692 0.99634 0.99709 0.99528 0.99384 0.99502
## [1171] 0.99667 0.99522 0.99649 0.99716 0.99716 0.99541 0.99572 0.99318 0.99346
## [1180] 0.99599 0.99599 0.99478 0.99754 0.99572 0.99538 0.99346 0.99630 0.99346
## [1189] 0.99538 0.99616 0.99652 0.99551 0.99439 0.99551 0.99588 0.99633 0.99686
## [1198] 0.99458 0.99510 0.99686 0.99458 0.99419 0.99516 0.99878 0.99534 0.99534
## [1207] 0.99534 0.99752 0.99534 0.99428 0.99498 0.99570 0.99498 0.99659 0.99628
## [1216] 0.99488 0.99677 0.99408 0.99600 0.99478 0.99734 0.99734 0.99678 0.99638
## [1225] 0.99920 0.99922 0.99592 0.99769 0.99157 0.99718 0.99470 0.99621 0.99718
## [1234] 0.99614 0.99242 0.99572 0.99659 0.99242 0.99798 0.99488 0.99494 0.99729
## [1243] 0.99414 0.99830 0.99721 0.99655 0.99502 0.99655 0.99490 0.99514 0.99514
## [1252] 0.99630 0.99627 0.99569 0.99628 0.99358 0.99499 0.99633 0.99538 0.99538
## [1261] 0.99632 0.99437 0.99726 0.99780 0.99456 0.99564 0.99564 0.99600 0.99668
## [1270] 0.99080 0.99084 0.99350 0.99385 0.99494 0.99440 0.99688 0.99566 0.99636
## [1279] 0.99688 0.99480 0.99560 0.99560 0.99619 0.99734 0.99476 0.99734 0.99328
## [1288] 0.99286 0.99914 0.99914 0.99521 0.99638 0.99362 0.99672 0.99638 0.99558
## [1297] 0.99558 0.99323 0.99191 0.99476 0.99444 0.99598 0.99576 0.99501 0.99550
## [1306] 0.99612 0.99790 0.99524 0.99790 0.99600 0.99612 0.99290 0.99532 0.99558
## [1315] 0.99556 0.99616 0.99258 0.99638 0.99616 0.99652 0.99796 0.99258 0.99392
## [1324] 0.99495 0.99480 0.99480 0.99480 0.99480 0.99550 0.99616 0.99616 0.99668
## [1333] 0.99581 0.99760 0.99608 0.99387 0.99448 0.99448 0.99448 0.99538 0.99538
## [1342] 0.99538 0.99589 0.99538 0.99852 0.99613 0.99472 0.99587 0.99587 0.99518
## [1351] 0.99654 0.99332 0.99690 0.99690 0.99568 0.99464 0.99464 0.99648 0.99736
## [1360] 0.99704 0.99699 0.99724 0.99704 0.99652 0.99500 0.99710 0.99576 0.99725
## [1369] 0.99656 0.99396 0.99623 0.99476 0.99623 0.99664 0.99471 0.99586 0.99460
## [1378] 0.99530 0.99609 0.99557 0.99557 0.99534 0.99613 0.99613 0.99593 0.99668
## [1387] 0.99610 0.99610 0.99718 0.99524 0.99292 0.99612 0.99420 0.99612 0.99669
## [1396] 0.99745 0.99745 0.99584 0.99660 0.99560 0.99620 0.99620 0.99630 0.99600
## [1405] 0.99850 0.99520 0.99740 0.99500 0.99500 0.99500 0.99360 0.99630 0.99740
## [1414] 0.99630 0.99940 0.99660 0.99940 0.99520 0.99500 0.99560 0.99500 0.99650
## [1423] 0.99560 0.99680 0.99740 0.99740 0.99710 0.99570 0.99620 0.99600 0.99560
## [1432] 0.99580 0.99440 0.99550 1.00369 1.00369 0.99914 0.99577 0.99600 0.99566
## [1441] 0.99470 0.99713 0.99712 0.99322 0.99566 0.99713 0.99712 0.99701 0.99683
## [1450] 0.99472 0.99470 0.99732 0.99374 0.99706 0.99974 0.99467 0.99236 0.99706
## [1459] 0.99603 0.99458 0.99724 0.99664 0.99545 0.99522 0.99580 0.99580 0.99728
## [1468] 0.99648 0.99728 0.99705 0.99578 0.99334 0.99656 0.99336 1.00242 0.99182
## [1477] 1.00242 0.99182 0.99808 0.99828 0.99498 0.99828 0.99719 0.99542 0.99592
## [1486] 0.99606 0.99546 0.99496 0.99420 0.99448 0.99344 0.99420 0.99348 0.99636
## [1495] 0.99459 0.99492 0.99636 0.99508 0.99582 0.99508 0.99508 0.99642 0.99638
## [1504] 0.99555 0.99605 0.99600 0.99562 0.99605 0.99814 0.99410 0.99661 0.99712
## [1513] 0.99588 0.99294 0.99842 0.99842 0.99633 0.99489 0.99647 0.99665 0.99489
## [1522] 0.99585 0.99633 0.99530 0.99522 0.99552 0.99553 0.99510 0.99714 0.99608
## [1531] 0.99444 0.99631 0.99573 0.99717 0.99397 0.99590 0.99528 0.99484 0.99538
## [1540] 0.99714 0.99646 0.99666 0.99472 0.99758 0.99550 0.99531 0.99575 0.99306
## [1549] 0.99783 0.99419 0.99783 0.99768 0.99586 0.99765 0.99627 0.99514 0.99636
## [1558] 0.99627 0.99787 0.99622 0.99622 0.99622 0.99546 0.99546 0.99546 0.99489
## [1567] 0.99494 0.99546 0.99629 0.99396 0.99340 0.99514 0.99632 0.99467 0.99677
## [1576] 0.99474 0.99588 0.99622 0.99540 0.99402 0.99470 0.99402 0.99362 0.99578
## [1585] 0.99484 0.99494 0.99492 0.99483 0.99414 0.99770 0.99314 0.99402 0.99574
## [1594] 0.99651 0.99490 0.99512 0.99574 0.99547 0.99549
sd_density <- sd(density)
sd_density
## [1] 0.001887334
var_density <- sd(density)/sqrt(length(density))
var_density
## [1] 4.71981e-05

The variability of the estimate based on the population is 4.71981e-05.

Based on the sample estimate, the μ value is very close to one, and the variability is close to zero, so the Central Limit Theorem can be used as the distribution appears to be normal. The histogram below also shows a normal distribution for the sample of density.

hist(density)

(c) Use the CLT to give a 95% confidence interval for μ.

95% falls within 2 standard deviations.

# Lower confidence interval
lower_conf <- mu_density - 2*(var_density)
lower_conf
## [1] 0.9966523

The lower confidence level for 95% confidence interval for the population is 0.9967 (rounded to four decimal places).

# Upper confidence interval
upper_conf <- mu_density + 2*(var_density)
upper_conf
## [1] 0.9968411

The upper confidence level for 95% confidence interval for the population is 0.9968 (rounded to four decimal places).

Therefore, the 95% confidence interval for μ is (0.9967, 0.9968).

(d) Use the bootstrap method to do parts b and c, and compare the results with those obtained from the CLT. State your findings.

# Keep the same sample size as the above estimate
mu_density.set <- NULL
for (k in 1:2500) {
  density.bootstrap <- sample(density, size=1599, replace=T)
mu_density <- mean(density.bootstrap)
mu_density.set[k] <- mu_density
}

sd(mu_density.set)
## [1] 4.703773e-05

The variability from the bootstrap method can be seen above. This is slightly less than the variability when using the Central Limit Theorem; in fact, they are almost equal.

conf_quantile <- quantile(mu_density.set, probs=c(0.025, 0.975))
conf_quantile
##      2.5%     97.5% 
## 0.9966552 0.9968392

The lower and upper confidence levels for 95% using the bootstrap method can be seen above.

(e) Can we use a normal distribution to model “density”? If yes, what are the maximum likelihood estimates of the mean and standard deviation? Please provide their standard errors as well.

Yes, a normal distribution can be used to model “density”. This is evident in the histogram below.

The function MLE for the original “density” values is not stable because the values are too small. To accommodate these values, multiply the variable “density” by ten to flatten the curve. Once the estimates and standard errors are calculated, divide those values by ten to achieve the accurate values.

# Using mle for the original 'density' values is not stable because the values are too small
# Multiply variable 'density' by 10 to flatten the curve
# Divide the estimates and standard errors by 10 to get the new, accurate value
# Divide variance by 10^2 
# SD and SE are on the same scale of x
# Var(X) = E(X - μ)^2

hist(density)

# Too steep

density_v2 <- density*10
density_v2
##    [1]  9.9780  9.9680  9.9700  9.9800  9.9780  9.9780  9.9640  9.9460  9.9680
##   [10]  9.9780  9.9590  9.9780  9.9430  9.9740  9.9860  9.9860  9.9690  9.9680
##   [19]  9.9740  9.9690  9.9680  9.9820  9.9660  9.9680  9.9680  9.9550  9.9620
##   [28]  9.9660  9.9720  9.9640  9.9580  9.9660  9.9660  9.9930  9.9570  9.9860
##   [37]  9.9750  9.9680  9.9400  9.9780  9.9780  9.9760  9.9680  9.9680  9.9620
##   [46]  9.9340  9.9700  9.9690  9.9580  9.9540  9.9710  9.9560  9.9550  9.9700
##   [55]  9.9550  9.9780  9.9710  9.9830  9.9750  9.9620  9.9800  9.9680  9.9680
##   [64]  9.9660  9.9620  9.9620  9.9680  9.9620  9.9690  9.9620  9.9670  9.9620
##   [73]  9.9610  9.9760  9.9840  9.9860  9.9860  9.9660  9.9580  9.9720  9.9580
##   [82]  9.9740  9.9700  9.9690  9.9590  9.9610  9.9720  9.9660  9.9780  9.9780
##   [91]  9.9640  9.9720  9.9720  9.9660  9.9380  9.9320  9.9650  9.9630  9.9670
##  [100]  9.9720  9.9720  9.9590  9.9720  9.9670  9.9600  9.9670  9.9730  9.9690
##  [109]  9.9760  9.9690  9.9640  9.9640  9.9640  9.9880  9.9640  9.9660  9.9780
##  [118]  9.9700  9.9620  9.9590  9.9620  9.9620  9.9800  9.9760  9.9600  9.9840
##  [127]  9.9640  9.9640  9.9620  9.9550  9.9680  9.9370  9.9370  9.9520  9.9590
##  [136]  9.9650  9.9680  9.9720  9.9620  9.9620  9.9650  9.9680  9.9160  9.9540
##  [145]  9.9160  9.9680  9.9440  9.9680  9.9590  9.9750  9.9580  9.9960  9.9500
##  [154]  9.9500  9.9730  9.9730  9.9730  9.9730  9.9690  9.9680  9.9590  9.9650
##  [163]  9.9640  9.9820  9.9810  9.9610  9.9560  9.9560  9.9530  9.9640  9.9720
##  [172]  9.9720  9.9720  9.9610  9.9610  9.9580  9.9610  9.9720  9.9690  9.9690
##  [181]  9.9690  9.9720  9.9720  9.9710  9.9700  9.9710  9.9720  9.9760  9.9680
##  [190]  9.9680  9.9760  9.9740  9.9690  9.9640  9.9640  9.9680  9.9680  9.9810
##  [199]  9.9240  9.9480  9.9695  9.9750  9.9545  9.9610  9.9615  9.9940  9.9940
##  [208]  9.9625  9.9660  9.9800  9.9585  9.9685  9.9800  9.9590  9.9740  9.9740
##  [217]  9.9620  9.9670  9.9570  9.9655  9.9640  9.9570  9.9525  9.9815  9.9745
##  [226]  9.9615  9.9640  9.9840  9.9615  9.9685  9.9270  9.9625  9.9800  9.9685
##  [235]  9.9685  9.9675  9.9675  9.9675  9.9675  9.9685  9.9710  9.9925  9.9565
##  [244] 10.0005 10.0005  9.9830  9.9685  9.9630  9.9615  9.9830  9.9850  9.9720
##  [253]  9.9860  9.9590  9.9720  9.9675  9.9800  9.9680  9.9680  9.9965  9.9625
##  [262]  9.9565  9.9575  9.9630  9.9990  9.9680 10.0025  9.9730  9.9870  9.9960
##  [271]  9.9650  9.9960  9.9935  9.9735  9.9915  9.9650  9.9870  9.9960  9.9760
##  [280]  9.9910  9.9860  9.9720  9.9710  9.9910 10.0015 10.0015  9.9970  9.9670
##  [289]  9.9760 10.0100  9.9760  9.9790  9.9940  9.9640 10.0140 10.0010  9.9810
##  [298]  9.9855  9.9930  9.9845  9.9650  9.9730  9.9940  9.9600  9.9730  9.9980
##  [307]  9.9660  9.9940  9.9940  9.9680  9.9980  9.9600  9.9815  9.9760  9.9645
##  [316]  9.9620  9.9960  9.9865  9.9890  9.9865  9.9890  9.9975  9.9735  9.9900
##  [325] 10.0150 10.0150  9.9780  9.9800 10.0020  9.9810  9.9800  9.9800  9.9730
##  [334]  9.9580  9.9630  9.9920  9.9480  9.9740 10.0080  9.9970 10.0000  9.9720
##  [343]  9.9820  9.9820 10.0060  9.9790  9.9550  9.9860  9.9790  9.9940 10.0040
##  [352]  9.9940  9.9740 10.0180  9.9120  9.9550 10.0010  9.9700 10.0000 10.0100
##  [361]  9.9730  9.9820  9.9920  9.9880 10.0220  9.9790 10.0220 10.0000  9.9980
##  [370]  9.9620  9.9750  9.9670  9.9670  9.9590 10.0140  9.9840 10.0030  9.9620
##  [379]  9.9880  9.9790  9.9740 10.0140  9.9740  9.9740  9.9800  9.9790  9.9810
##  [388]  9.9720  9.9810  9.9820  9.9240 10.0140  9.9800  9.9700  9.9970 10.0040
##  [397]  9.9940  9.9880  9.9880  9.9630  9.9940  9.9490 10.0000  9.9940  9.9740
##  [406]  9.9660  9.9810  9.9960  9.9700  9.9810  9.9870  9.9870  9.9660  9.9860
##  [415]  9.9820 10.0140  9.9700  9.9560  9.9960  9.9760  9.9720  9.9520  9.9550
##  [424]  9.9780  9.9550  9.9520  9.9490  9.9880  9.9780  9.9970  9.9780  9.9740
##  [433]  9.9580 10.0040  9.9960 10.0040  9.9580  9.9860  9.9960  9.9510  9.9870
##  [442]  9.9880 10.0320  9.9630  9.9340  9.9860  9.9960  9.9680  9.9670  9.9940
##  [451]  9.9940  9.9790  9.9680  9.9980  9.9520  9.9880  9.9860  9.9880  9.9980
##  [460] 10.0080  9.9760  9.9820  9.9700  9.9720  9.9870 10.0060  9.9820  9.9470
##  [469] 10.0000  9.9520  9.9960  9.9700  9.9950  9.9710  9.9820  9.9880  9.9800
##  [478]  9.9770  9.9880  9.9840 10.0260  9.9640  9.9860  9.9860  9.9700  9.9760
##  [487]  9.9760  9.9820 10.0020  9.9840  9.9840  9.9520  9.9500 10.0020  9.9520
##  [496]  9.9720  9.9840  9.9660  9.9720 10.0020  9.9840  9.9900  9.9900  9.9760
##  [505]  9.9760  9.9680  9.9760 10.0000  9.9940  9.9860  9.9780  9.9940  9.9800
##  [514]  9.9730  9.9730 10.0100 10.0100  9.9940  9.9720  9.9660  9.9820  9.9800
##  [523]  9.9790  9.9780  9.9760  9.9980  9.9660  9.9620  9.9880  9.9740  9.9900
##  [532] 10.0040 10.0040  9.9560 10.0000  9.9900  9.9740  9.9720 10.0140  9.9960
##  [541]  9.9880  9.9880  9.9660  9.9930 10.0080  9.9820  9.9830  9.9870  9.9940
##  [550]  9.9750  9.9580  9.9800  9.9800  9.9340 10.0315 10.0315 10.0020 10.0315
##  [559] 10.0020 10.0210  9.9940  9.9780  9.9820  9.9710 10.0210  9.9940  9.9910
##  [568]  9.9910  9.9900  9.9460 10.0030  9.9460  9.9780  9.9910  9.9920  9.9930
##  [577]  9.9780  9.9820  9.9820  9.9760 10.0020 10.0020 10.0000  9.9760 10.0020
##  [586]  9.9800  9.9860  9.9670  9.9170  9.9760  9.9870  9.9220  9.9870 10.0040
##  [595]  9.9780  9.9980  9.9940  9.9800  9.9670 10.0000  9.9620 10.0060  9.9750
##  [604] 10.0060  9.9840  9.9840  9.9730  9.9820 10.0260  9.9560  9.9830 10.0060
##  [613]  9.9650  9.9620  9.9690  9.9970  9.9970  9.9820 10.0060  9.9880  9.9760
##  [622]  9.9760  9.9740  9.9740  9.9970  9.9970  9.9880  9.9880  9.9760  9.9640
##  [631]  9.9760  9.9880  9.9640 10.0100  9.9640  9.9540  9.9790  9.9780  9.9640
##  [640]  9.9700  9.9910  9.9920  9.9910  9.9920  9.9910  9.9840  9.9720  9.9670
##  [649]  9.9640  9.9480  9.9860 10.0100  9.9760  9.9760  9.9790 10.0040  9.9860
##  [658]  9.9800  9.9730  9.9700  9.9730  9.9780  9.9720  9.9740 10.0000  9.9810
##  [667]  9.9800  9.9880  9.9660  9.9880  9.9590  9.9680  9.9800  9.9680  9.9840
##  [676]  9.9840  9.9840  9.9790  9.9830  9.9720 10.0040  9.9620  9.9800  9.9700
##  [685]  9.9800  9.9700  9.9700  9.9980  9.9620  9.9760  9.9660  9.9980  9.9790
##  [694]  9.9840  9.9840  9.9210  9.9720  9.9720 10.0010  9.9860  9.9840  9.9720
##  [703]  9.9700  9.9720  9.9800  9.9900  9.9560  9.9660  9.9600  9.9830  9.9850
##  [712]  9.9980  9.9920  9.9760  9.9800  9.9670  9.9760  9.9680  9.9760  9.9760
##  [721]  9.9760  9.9820  9.9680  9.9650  9.9580  9.9760  9.9940  9.9700  9.9700
##  [730]  9.9500  9.9820  9.9940  9.9660  9.9800  9.9870  9.9630  9.9630 10.0020
##  [739]  9.9830  9.9900  9.9650  9.9788  9.9720 10.0024 10.0010  9.9768  9.9780
##  [748]  9.9782  9.9761  9.9768  9.9803  9.9803  9.9785  9.9803  9.9656  9.9525
##  [757]  9.9488  9.9656  9.9656  9.9823  9.9779  9.9738  9.9701  9.9738  9.9888
##  [766]  9.9888  9.9738  9.9938  9.9744  9.9668  9.9744  9.9780  9.9782  9.9730
##  [775]  9.9727  9.9586  9.9612  9.9610  9.9788  9.9745  9.9676  9.9732  9.9814
##  [784]  9.9732  9.9746  9.9820  9.9820  9.9910  9.9910  9.9800  9.9708  9.9818
##  [793]  9.9745  9.9639  9.9531  9.9786  9.9746  9.9526  9.9870  9.9870  9.9641
##  [802]  9.9735  9.9264  9.9710  9.9682  9.9356  9.9386  9.9356  9.9702  9.9693
##  [811]  9.9562 10.0012  9.9818  9.9462  9.9939  9.9818  9.9840  9.9545  9.9632
##  [820]  9.9976  9.9606  9.9154  9.9730  9.9730  9.9682  9.9624  9.9510  9.9624
##  [829]  9.9417  9.9376  9.9632  9.9376  9.9832  9.9836  9.9694  9.9655  9.9064
##  [838]  9.9064  9.9672  9.9647  9.9736  9.9629  9.9708  9.9630  9.9590  9.9689
##  [847]  9.9689  9.9770  9.9689  9.9689  9.9708  9.9708  9.9801  9.9652  9.9652
##  [856]  9.9538  9.9652  9.9594  9.9686  9.9438  9.9746  9.9357  9.9628  9.9746
##  [865]  9.9746  9.9748  9.9438  9.9438  9.9438  9.9578  9.9371  9.9522  9.9576
##  [874]  9.9552  9.9664  9.9614  9.9517  9.9371  9.9787  9.9745  9.9576  9.9533
##  [883]  9.9536  9.9745  9.9787  9.9824  9.9836  9.9577  9.9491 10.0289  9.9576
##  [892]  9.9743  9.9774  9.9743  9.9745  9.9550  9.9444  9.9550  9.9444  9.9892
##  [901]  9.9562  9.9736  9.9736  9.9620  9.9620  9.9800  9.9640  9.9480  9.9528
##  [910]  9.9331  9.9577  9.9901  9.9674  9.9639  9.9331  9.9512  9.9395  9.9824
##  [919]  9.9640  9.9504  9.9786  9.9640  9.9504  9.9824  9.9516  9.9604  9.9786
##  [928]  9.9736  9.9516  9.9468  9.9746  9.9748  9.9710  9.9748  9.9746  9.9543
##  [937]  9.9543  9.9791  9.9356  9.9425  9.9509  9.9484  9.9834  9.9864  9.9498
##  [946]  9.9566  9.9745  9.9408  9.9552  9.9552  9.9552  9.9408  9.9536  9.9458
##  [955]  9.9538  9.9648  9.9568  9.9613  9.9519  9.9735  9.9518  9.9592  9.9654
##  [964]  9.9546  9.9518  9.9554  9.9604  9.9733  9.9430  9.9669  9.9724  9.9724
##  [973]  9.9643  9.9605  9.9658  9.9700  9.9700  9.9801  9.9416  9.9690  9.9774
##  [982]  9.9712  9.9418  9.9774  9.9690  9.9562  9.9470  9.9693  9.9596  9.9556
##  [991]  9.9596  9.9694  9.9554  9.9694  9.9918  9.9697  9.9378  9.9378  9.9554
## [1000]  9.9162  9.9495  9.9676  9.9516  9.9280  9.9603  9.9280  9.9516  9.9516
## [1009]  9.9549  9.9722  9.9354  9.9570  9.9604  9.9635  9.9454  9.9598  9.9486
## [1018]  9.9007  9.9007  9.9636  9.9642  9.9642  9.9584  9.9506  9.9568  9.9822
## [1027]  9.9364  9.9378  9.9586  9.9568  9.9488  9.9514  9.9854  9.9592  9.9739
## [1036]  9.9683  9.9356  9.9672  9.9530  9.9692  9.9756  9.9547  9.9692  9.9859
## [1045]  9.9294  9.9438  9.9612  9.9634  9.9702  9.9704  9.9634  9.9702  9.9258
## [1054]  9.9426  9.9747  9.9747  9.9586  9.9784  9.9710  9.9586  9.9810  9.9462
## [1063]  9.9560  9.9565  9.9418  9.9630  9.9358  9.9572  9.9572  9.9700  9.9498
## [1072]  9.9892  9.9680  9.9720  9.9892  9.9769  9.9534  9.9817  9.9817  9.9316
## [1081]  9.9471  9.9316  9.9685  9.9617  9.9685  9.9529  9.9738  9.9400  9.9735
## [1090]  9.9735  9.9451  9.9546  9.9479  9.9615  9.9655  9.9772  9.9655  9.9666
## [1099]  9.9358  9.9666  9.9392  9.9388  9.9402  9.9388  9.9360  9.9374  9.9376
## [1108]  9.9523  9.9855  9.9820  9.9593  9.9471  9.9396  9.9698  9.9020  9.9572
## [1117]  9.9572  9.9572  9.9252  9.9256  9.9235  9.9352  9.9220  9.9674  9.9557
## [1126]  9.9394  9.9150  9.9379  9.9840  9.9798  9.9770  9.9341  9.9330  9.9684
## [1135]  9.9524  9.9460  9.9774  9.9774  9.9786  9.9764  9.9690  9.9624  9.9354
## [1144]  9.9672  9.9588  9.9672  9.9600  9.9702  9.9526  9.9585  9.9473  9.9352
## [1153]  9.9616  9.9622  9.9544  9.9616  9.9524  9.9240  9.9572  9.9728  9.9676
## [1162]  9.9551  9.9434  9.9692  9.9692  9.9634  9.9709  9.9528  9.9384  9.9502
## [1171]  9.9667  9.9522  9.9649  9.9716  9.9716  9.9541  9.9572  9.9318  9.9346
## [1180]  9.9599  9.9599  9.9478  9.9754  9.9572  9.9538  9.9346  9.9630  9.9346
## [1189]  9.9538  9.9616  9.9652  9.9551  9.9439  9.9551  9.9588  9.9633  9.9686
## [1198]  9.9458  9.9510  9.9686  9.9458  9.9419  9.9516  9.9878  9.9534  9.9534
## [1207]  9.9534  9.9752  9.9534  9.9428  9.9498  9.9570  9.9498  9.9659  9.9628
## [1216]  9.9488  9.9677  9.9408  9.9600  9.9478  9.9734  9.9734  9.9678  9.9638
## [1225]  9.9920  9.9922  9.9592  9.9769  9.9157  9.9718  9.9470  9.9621  9.9718
## [1234]  9.9614  9.9242  9.9572  9.9659  9.9242  9.9798  9.9488  9.9494  9.9729
## [1243]  9.9414  9.9830  9.9721  9.9655  9.9502  9.9655  9.9490  9.9514  9.9514
## [1252]  9.9630  9.9627  9.9569  9.9628  9.9358  9.9499  9.9633  9.9538  9.9538
## [1261]  9.9632  9.9437  9.9726  9.9780  9.9456  9.9564  9.9564  9.9600  9.9668
## [1270]  9.9080  9.9084  9.9350  9.9385  9.9494  9.9440  9.9688  9.9566  9.9636
## [1279]  9.9688  9.9480  9.9560  9.9560  9.9619  9.9734  9.9476  9.9734  9.9328
## [1288]  9.9286  9.9914  9.9914  9.9521  9.9638  9.9362  9.9672  9.9638  9.9558
## [1297]  9.9558  9.9323  9.9191  9.9476  9.9444  9.9598  9.9576  9.9501  9.9550
## [1306]  9.9612  9.9790  9.9524  9.9790  9.9600  9.9612  9.9290  9.9532  9.9558
## [1315]  9.9556  9.9616  9.9258  9.9638  9.9616  9.9652  9.9796  9.9258  9.9392
## [1324]  9.9495  9.9480  9.9480  9.9480  9.9480  9.9550  9.9616  9.9616  9.9668
## [1333]  9.9581  9.9760  9.9608  9.9387  9.9448  9.9448  9.9448  9.9538  9.9538
## [1342]  9.9538  9.9589  9.9538  9.9852  9.9613  9.9472  9.9587  9.9587  9.9518
## [1351]  9.9654  9.9332  9.9690  9.9690  9.9568  9.9464  9.9464  9.9648  9.9736
## [1360]  9.9704  9.9699  9.9724  9.9704  9.9652  9.9500  9.9710  9.9576  9.9725
## [1369]  9.9656  9.9396  9.9623  9.9476  9.9623  9.9664  9.9471  9.9586  9.9460
## [1378]  9.9530  9.9609  9.9557  9.9557  9.9534  9.9613  9.9613  9.9593  9.9668
## [1387]  9.9610  9.9610  9.9718  9.9524  9.9292  9.9612  9.9420  9.9612  9.9669
## [1396]  9.9745  9.9745  9.9584  9.9660  9.9560  9.9620  9.9620  9.9630  9.9600
## [1405]  9.9850  9.9520  9.9740  9.9500  9.9500  9.9500  9.9360  9.9630  9.9740
## [1414]  9.9630  9.9940  9.9660  9.9940  9.9520  9.9500  9.9560  9.9500  9.9650
## [1423]  9.9560  9.9680  9.9740  9.9740  9.9710  9.9570  9.9620  9.9600  9.9560
## [1432]  9.9580  9.9440  9.9550 10.0369 10.0369  9.9914  9.9577  9.9600  9.9566
## [1441]  9.9470  9.9713  9.9712  9.9322  9.9566  9.9713  9.9712  9.9701  9.9683
## [1450]  9.9472  9.9470  9.9732  9.9374  9.9706  9.9974  9.9467  9.9236  9.9706
## [1459]  9.9603  9.9458  9.9724  9.9664  9.9545  9.9522  9.9580  9.9580  9.9728
## [1468]  9.9648  9.9728  9.9705  9.9578  9.9334  9.9656  9.9336 10.0242  9.9182
## [1477] 10.0242  9.9182  9.9808  9.9828  9.9498  9.9828  9.9719  9.9542  9.9592
## [1486]  9.9606  9.9546  9.9496  9.9420  9.9448  9.9344  9.9420  9.9348  9.9636
## [1495]  9.9459  9.9492  9.9636  9.9508  9.9582  9.9508  9.9508  9.9642  9.9638
## [1504]  9.9555  9.9605  9.9600  9.9562  9.9605  9.9814  9.9410  9.9661  9.9712
## [1513]  9.9588  9.9294  9.9842  9.9842  9.9633  9.9489  9.9647  9.9665  9.9489
## [1522]  9.9585  9.9633  9.9530  9.9522  9.9552  9.9553  9.9510  9.9714  9.9608
## [1531]  9.9444  9.9631  9.9573  9.9717  9.9397  9.9590  9.9528  9.9484  9.9538
## [1540]  9.9714  9.9646  9.9666  9.9472  9.9758  9.9550  9.9531  9.9575  9.9306
## [1549]  9.9783  9.9419  9.9783  9.9768  9.9586  9.9765  9.9627  9.9514  9.9636
## [1558]  9.9627  9.9787  9.9622  9.9622  9.9622  9.9546  9.9546  9.9546  9.9489
## [1567]  9.9494  9.9546  9.9629  9.9396  9.9340  9.9514  9.9632  9.9467  9.9677
## [1576]  9.9474  9.9588  9.9622  9.9540  9.9402  9.9470  9.9402  9.9362  9.9578
## [1585]  9.9484  9.9494  9.9492  9.9483  9.9414  9.9770  9.9314  9.9402  9.9574
## [1594]  9.9651  9.9490  9.9512  9.9574  9.9547  9.9549
hist(density_v2)

# Flatten the curve

# Density function for the first observation
dnorm(density_v2[1], mean=mean(density_v2), sd=sd(density_v2))
## [1] 18.08945
library(stats4)
sd_density_v2 <- sd(density_v2)

minuslog.lik <- function(mu, sigma) {
  log.lik <- 0
  for(i in 1:1599) {
    log.lik <- log.lik + log(dnorm(density_v2[i], mean = mu, sd = sigma))
  }
  return(-log.lik)
}

minuslog.lik(80, 20)
## [1] 16062.54
minuslog.lik(100, 30)
## [1] 14108.6
minuslog.lik(0, 1)
## [1] 80900.31
est <- stats4::mle(minuslog = minuslog.lik,
                   start = list(mu = mean(density_v2),
                                sigma = sd(density_v2)))

summary(est)
## Maximum likelihood estimation
## 
## Call:
## stats4::mle(minuslogl = minuslog.lik, start = list(mu = mean(density_v2), 
##     sigma = sd(density_v2)))
## 
## Coefficients:
##         Estimate   Std. Error
## mu    9.96746679 0.0004719810
## sigma 0.01887334 0.0003296881
## 
## -2 log L: -8159.31
# Maximum likelihood estimation

From the estimate for density, the MLE estimate of the mean is 9.9674 (rounded to four decimal places); however, we need to divide this number by ten to ensure accuracy. Therefore, the MLE estimate of the mean for density is 0.9967 (rounded to four decimal places). The MLE estimate of sigma, or the standard deviation, is 0.0189 (rounded to four decimal places); however we need to divide this number by ten to ensure accuracy. Therefore, the MLE estimate of the standard deviation for density is 0.0019 (rounded to four decimal places).

The standard error for the mean is 0.0005 (rounded to four decimal places); however, divided by ten to ensure accuracy, the error is 0.0001 (rounded to four decimal places). The standard error for the standard deviation is 0.0003 (rounded to four decimal places); however, divided by ten to ensure accuracy, the error is 0.0000 (rounded to four decimal places).

Suppose the population mean of the variable “residual sugar” is μ, answer the following questions.

(a) Provide an estimate of μ based on the sample;

# Mean of the sample
mu_sugar <- mean(`residual sugar`)
mu_sugar
## [1] 2.538806

The estimate of μ based on the sample mean of the variable “residual sugar” is 2.5388 (rounded to four decimal places.).

(b) Noting that the sample distribution of “residual sugar” is highly skewed, can we use the CLT to quantify the variability of your estimate? Can we use the CLT to give a 95% confidence interval for μ? If yes, please give your solution. If no, explain why.

hist <- hist(`residual sugar`)

From the above histogram, it is evident that the distribution of residual sugar is highly skewed to the right. Even though the data is skewed, the means will be normally distributed. Therefore, yes, the CLT can be used to quantify the variability of the estimate.

# Variance of the sample
print(`residual sugar`)
##    [1]  1.90  2.60  2.30  1.90  1.90  1.80  1.60  1.20  2.00  6.10  1.80  6.10
##   [13]  1.60  1.60  3.80  3.90  1.80  1.70  4.40  1.80  1.80  2.30  1.60  2.30
##   [25]  2.40  1.40  1.80  1.60  1.90  2.00  2.40  2.50  2.30 10.70  1.80  5.50
##   [37]  2.40  2.10  1.50  5.90  5.90  2.80  2.60  2.20  1.80  2.10  2.20  1.60
##   [49]  1.60  1.40  1.70  2.20  2.10  3.00  2.80  3.80  3.40  5.10  2.30  2.40
##   [61]  2.20  1.80  1.90  2.00  4.65  4.65  1.50  1.60  2.00  1.90  1.90  2.10
##   [73]  1.90  2.10  2.50  2.20  2.20  2.40  2.00  1.50  1.60  1.90  2.00  1.80
##   [85]  1.80  2.20  1.90  1.90  2.10  1.80  1.90  1.90  2.00  1.90  1.40  2.30
##   [97]  3.00  2.00  2.50  1.90  2.10  1.90  1.90  2.10  2.20  2.10  1.70  1.70
##  [109]  2.50  2.00  1.80  2.20  2.20  2.30  1.80  2.20  1.90  2.00  2.20  1.80
##  [121]  1.70  2.20  2.50  2.60  1.60  1.90  1.70  1.80  1.80  1.80  2.00  2.30
##  [133]  2.30  1.50  2.20  1.90  1.80  2.00  2.10  2.00  1.90  1.80  1.80  1.70
##  [145]  1.80  1.80  1.80  1.60  2.30  2.80  2.10  3.40  1.80  1.80  5.50  5.50
##  [157]  5.50  5.50  2.20  1.90  2.00  1.30  1.70  7.30  7.20  1.70  2.10  1.60
##  [169]  2.10  1.80  1.80  2.00  2.00  1.90  2.00  1.50  2.00  2.30  2.50  2.40
##  [181]  2.40  2.00  2.50  1.80  1.90  2.00  2.00  2.60  2.00  1.90  2.90  1.90
##  [193]  3.80  2.20  2.20  2.00  2.40  2.00  1.20  2.10  1.40  2.10  1.50  1.60
##  [205]  1.60  2.60  2.60  1.80  2.70  2.10  2.00  2.80  2.10  2.20  2.40  5.60
##  [217]  2.00  2.20  1.90  2.40  2.00  2.00  1.50  2.00  2.00  2.60  2.00  2.60
##  [229]  2.60  2.60  1.60  1.80  2.80  2.60  2.30  1.90  1.90  1.90  1.90  2.30
##  [241]  1.70  2.10  1.80  2.20  2.20  2.00  1.90  2.30  1.70  2.00  1.60  1.80
##  [253]  3.10  1.90  1.80  3.20  2.20  2.10  1.80  2.60  1.70  2.00  1.70  1.80
##  [265]  2.40  1.80  3.30  3.60  3.00  4.00  4.00  4.00  4.00  2.40  7.00  4.00
##  [277]  3.00  4.00  6.40  5.60  3.60  3.50  3.00  5.60  3.40  3.40  2.00  3.00
##  [289]  2.50  3.30  2.50  2.00  2.70  2.40  3.20  2.50  2.60  2.00  2.30  2.10
##  [301]  2.60  1.50  2.60  1.60  2.10  2.50  2.20  2.40  2.40  1.70  2.50  2.00
##  [313]  2.80  3.00  2.60  2.50  3.40  2.90  3.20  2.90  3.20  3.40  2.30  2.80
##  [325] 11.00 11.00  3.65  4.50  2.60  2.00  2.90  2.90  3.20  2.10  2.50  3.40
##  [337]  1.90  2.80  3.00  2.30  2.40  2.70  1.80  1.80  2.60  1.90  2.70  3.00
##  [349]  2.80  2.60  2.70  2.60  2.40  4.80  1.40  2.40  3.00  2.95  3.10  2.60
##  [361]  2.00  2.60  2.50  2.00  5.80  3.40  5.80  2.60  2.80  2.40  2.30  1.60
##  [373]  1.80  2.20  3.80  4.40  3.00  2.40  6.20  2.50  2.00  2.90  2.00  2.00
##  [385]  2.10  2.40  2.00  1.90  1.90  2.50  1.40  2.90  2.00  2.00  2.30  4.20
##  [397]  7.90  2.60  2.60  2.30  7.90  1.70  2.60  2.70  2.70  1.40  2.50  3.00
##  [409]  3.70  4.50  2.50  2.40  1.90  6.70  2.70  6.60  2.20  1.90  2.00  1.80
##  [421]  2.40  2.30  2.00  2.10  2.00  2.30  2.10  1.90  1.30  2.40  2.10  2.20
##  [433]  2.30  2.30  3.20  2.30  2.00  3.20  3.20  1.50  2.20  2.15  3.70  2.70
##  [445]  1.70  2.10  2.60  2.10  2.00  2.80  2.80  1.80  1.70  2.80  1.60  5.20
##  [457]  2.30  2.70  2.80  2.20  2.30  2.60  2.55  2.20  2.10  2.90  2.00  2.60
##  [469]  2.10  1.20  2.60  2.40  2.60  2.10  1.70  2.20  2.00  1.80  2.20  2.70
##  [481] 15.50  2.80  2.20  2.20  4.10  1.90  1.90  1.80  2.80  2.60  2.80  2.50
##  [493]  2.60  3.00  8.30  2.60  1.90  2.50  2.60  3.00  1.90  6.55  6.55  1.90
##  [505]  1.80  2.90  1.80  2.30  2.20  2.80  4.60  2.20  2.10  2.40  2.40  6.10
##  [517]  4.30  2.10  2.80  2.50  2.70  2.00  2.30  2.50  2.40  2.80  2.50  2.50
##  [529]  2.60  2.40  2.10  2.70  2.70  2.10  2.70  2.10  2.40  2.10  5.80  5.15
##  [541]  3.30  6.30  2.10  2.50  1.80  2.60  2.00  2.50  2.60  1.90  2.10  2.80
##  [553]  2.70  1.60  4.20  4.20  4.60  4.20  4.60  4.30  2.80  2.40  2.90  2.70
##  [565]  4.30  2.80  2.50  2.50  2.60  2.20  3.30  2.20  2.40  2.10  3.20  3.10
##  [577]  2.30  2.80  2.90  2.20  2.20  2.20  2.20  1.90  3.40  2.40  2.70  1.90
##  [589]  2.00  2.60  2.60  1.70  2.60  3.50  2.60  7.90  2.00  1.90  2.10  2.30
##  [601]  2.10  2.20  2.60  2.20  2.90  2.60  4.60  3.30  5.10  3.20  2.50  2.70
##  [613]  2.40  1.50  2.20  2.30  2.30  2.20  2.70  2.30  3.40  3.40  1.90  2.90
##  [625]  5.60  5.60  2.20  2.20  2.50  2.30  2.50  2.70  3.00  3.40  1.90  1.40
##  [637]  2.40  2.30  2.20  1.90  2.30  2.30  2.30  2.30  2.30  6.00  3.60  2.20
##  [649]  2.80  8.60  2.20  2.50  7.50  2.80  2.40  2.90  2.20  1.40  1.40  4.40
##  [661]  1.40  1.60  1.60  1.80  2.00  2.00  1.80  2.00  2.30  2.00  2.50  1.70
##  [673]  2.00  1.70  2.20  2.20  2.20  2.30  2.60  3.30  1.90  2.20  2.25  2.60
##  [685]  2.30  2.60  1.80  3.10  1.60  1.80  4.25  2.60  2.00  2.80  2.70  1.30
##  [697]  2.10  2.10  3.20  2.10  2.90  2.10  2.10  2.60  1.60  6.00  2.00  3.00
##  [709]  2.50  1.60  2.80  3.00  3.20  2.30  2.60  2.70  2.30  2.60  2.00  3.90
##  [721]  2.00  2.85  2.70  2.20  3.10  3.00  2.80  1.80  1.80  3.20  2.30  3.45
##  [733]  2.10  2.70  2.00  2.10  2.10  2.50  2.80  2.40  4.20  2.60  1.90  2.80
##  [745]  2.70  2.10  2.50  2.60  2.10  2.10  2.90  2.90  2.50  2.90  1.70  1.90
##  [757]  2.00  2.20  2.20  2.50  2.80  2.00  1.70  2.00  2.80  3.00  2.90  2.70
##  [769]  2.30  1.90  2.30  2.40  2.30  1.80  1.80  3.00  2.40  2.40  3.40  2.60
##  [781]  2.00  2.40  2.40  2.40  2.50  2.30  2.30  2.20  2.20  2.90  2.60  2.90
##  [793]  2.50  2.60  2.30  2.60  2.50  1.60  3.60  3.60  4.00  3.30  1.70  2.50
##  [805]  2.70  2.40  2.00  2.40  1.90  2.80  2.60  2.80  2.50  2.10  2.80  2.50
##  [817]  3.20  1.60  2.35  3.20  1.90  2.10  2.00  2.00  2.80  2.80  2.30  2.80
##  [829]  2.30  2.10  2.50  2.10  1.50  1.60  1.60  1.50  2.40  2.40  1.60  2.20
##  [841]  2.65  3.00  2.60  2.00  1.70  1.80  1.80  1.80  1.80  1.60  1.90  1.90
##  [853]  2.50  1.50  1.50  2.50  1.50  2.50  1.70  1.80  2.70  2.00  2.70  2.50
##  [865]  2.70  2.60  2.30  2.00  1.80  2.00  2.10  1.50  2.00  1.60  2.10  2.80
##  [877]  2.20  2.10  4.00  2.50  1.60  2.10  3.10  2.50  4.00  2.50  2.40  2.60
##  [889]  2.50  6.60  2.00  2.30  1.90  2.30  2.20  2.30  2.40  2.30  2.40  3.40
##  [901]  2.60  2.40  2.40  6.00  6.00  3.00  2.60  2.20  2.40  1.20  3.80  9.00
##  [913]  2.90  4.60  1.20  2.20  1.50  8.80  2.20  1.80  2.30  2.20  1.80  8.80
##  [925]  2.30  1.90  2.30  2.20  2.30  3.30  1.90  2.00  1.90  2.00  1.90  2.30
##  [937]  2.30  1.40  2.80  1.60  2.20  5.00  2.60  2.30  3.80  2.00  4.10  2.10
##  [949]  1.80  1.80  1.80  2.10  2.20  2.10  2.70  1.90  2.10  2.00  2.30  2.00
##  [961]  1.90  1.60  2.10  2.00  1.90  2.40  2.40  2.10  2.40  2.90  1.90  1.90
##  [973]  2.40  1.70  5.90  2.10  2.10  2.60  3.60  1.40  1.90  1.90  2.10  1.90
##  [985]  1.40  2.00  1.40  1.60  1.70  1.50  1.70  2.00  2.00  2.00  2.50  2.00
##  [997]  2.20  2.20  1.40  1.65  2.20  1.50  2.05  1.80  1.60  1.80  2.05  2.00
## [1009]  3.60  2.80  1.70  2.00  2.10  1.60  2.00  2.20  2.20  0.90  0.90  1.80
## [1021]  2.40  2.40  2.10  2.30  1.80  2.80  1.90  2.20  2.50  1.80  2.10  1.80
## [1033]  4.10  2.60  2.50  2.40  2.50  1.80  6.20  2.20  2.20  1.70  2.20  8.90
## [1045]  3.30  1.40  1.70  1.80  1.70  1.80  1.80  1.40  2.40  2.30  2.00  2.00
## [1057]  4.00  3.90  2.40  4.00  1.80  1.80  1.90  2.40  2.00  2.40  2.40  2.20
## [1069]  2.20  2.80  1.50  8.10  1.80  2.70  8.10  2.00  2.00  6.40  6.40  8.30
## [1081]  1.40  8.30  1.80  2.40  1.80  1.80  4.70  1.60  1.50  1.50  1.90  2.00
## [1093]  2.00  2.20  5.50  2.50  5.50  1.50  2.10  1.50  2.10  2.10  1.70  2.10
## [1105]  2.20  2.10  1.90  2.00  3.30  2.10  1.40  2.00  1.50  1.60  4.30  2.50
## [1117]  2.50  2.50  2.10  2.50  2.50  1.80  1.40  1.90  2.20  1.70  1.70  2.90
## [1129]  2.70  3.30  1.90  1.70  1.80  5.50  1.70  1.70  2.00  2.00  3.70  2.00
## [1141]  1.70  2.50  2.40  1.80  2.30  2.50  1.80  6.20  2.00  2.00  2.80  2.50
## [1153]  2.20  2.10  2.20  2.20  1.75  2.10  2.80  2.20  2.30  1.40  2.30  1.70
## [1165]  1.70  1.90  2.00  2.50  2.80  2.30  1.60  2.20  2.10  1.70  1.70  2.20
## [1177]  5.60  2.40  2.10  2.40  2.40  1.65  2.50  1.60  2.10  2.00  7.80  2.00
## [1189]  2.10  1.80  4.60  2.30  2.50  2.30  1.80  1.80  2.30  1.50  2.00  2.30
## [1201]  1.50  1.90  1.80  5.80  2.10  2.10  2.10  1.70  2.10  2.00  2.10  2.10
## [1213]  2.10  1.90  1.90  2.10  2.00  1.90  1.90  1.30  1.80  1.80  2.20  2.20
## [1225]  2.50  2.60  4.10  2.00  1.80  2.10  2.70  2.60  2.10  2.20  2.20 12.90
## [1237]  1.70  2.20  2.50  4.30  1.70  2.50  2.00  2.40 13.40  1.80  1.70  1.80
## [1249]  2.20  2.30  2.30  2.20  1.80  1.40  1.90  2.40  1.80  4.80  2.70  2.70
## [1261]  1.80  2.00  2.50  2.20  1.80  2.30  2.30  2.30  2.00  1.80  1.60  1.60
## [1273]  1.90  2.00  2.10  2.30  6.30  1.90  2.30  1.70  1.90  1.90  2.00  2.70
## [1285]  2.30  1.80  2.50  2.60  4.50  4.50  1.90  2.10  2.40  1.90  2.10  4.30
## [1297]  4.30  2.10  1.40  2.10  2.15  2.00  2.10  1.80  2.30  1.90  2.50  3.90
## [1309]  2.50  1.40  1.90  3.00  1.90  2.30  2.40  2.00  1.20  2.20  2.00  1.70
## [1321]  2.60  1.20  1.80  1.80  1.70  1.70  1.70  1.70  1.80  2.10  2.10  3.80
## [1333]  1.70  2.20  2.00  2.40  1.40  1.40  1.40  1.70  1.70  1.70  1.70  1.70
## [1345]  2.60  2.30  2.10  1.80  1.80  2.80  2.00  2.30  1.90  1.90  2.30  1.80
## [1357]  1.80  2.50  5.40  1.40  2.30  2.50  1.40  2.00  1.90  2.20  1.70  2.20
## [1369]  2.10  1.60  1.70  3.10  1.70  3.80  1.20  2.00  1.40  2.30  2.00  2.60
## [1381]  2.60  1.80  2.10  2.10  1.80  3.40  1.80  1.80  6.10  2.20  2.30  2.40
## [1393]  1.30  2.00  3.90  1.60  1.60  2.00  2.20  2.20  2.10  2.10  2.00  1.70
## [1405]  2.60  2.00  5.10  2.10  2.20  2.10  1.80  2.40  5.10  2.00  2.20  1.60
## [1417]  2.20  2.50  1.60  2.20  1.60  1.60  2.10  3.90  1.40  1.40  1.80  2.50
## [1429]  1.90  2.20  1.80  2.10  1.60  1.80 15.40 15.40  1.60  4.80  1.70  2.20
## [1441]  2.00  5.20  1.90  1.75  2.20  5.20  1.90  1.90  1.90  2.00  2.00  2.70
## [1453]  2.00  1.90  2.20  1.60  1.80  1.90  1.70  1.70  2.30  2.10  2.30  2.40
## [1465]  1.70  1.70  2.10  2.30  2.10  2.10  1.40  3.75  2.60  1.80 13.80  2.20
## [1477] 13.80  2.20  5.70  3.00  1.50  3.00  2.10  1.50  2.00  2.10  2.10  1.90
## [1489]  1.70  2.10  1.80  1.70  1.60  1.90  1.40  1.90  1.90  2.30  2.30  2.30
## [1501]  1.50  4.30  2.40  2.50  2.30  1.80  2.00  2.30  2.10  1.80  2.20  2.10
## [1513]  2.20  1.80  4.10  4.10  2.30  2.00  2.20  2.60  2.00  1.90  2.30  2.00
## [1525]  2.00  2.10  2.20  1.70  2.20  2.10  2.20  2.80  2.00  1.90  2.40  2.20
## [1537]  1.90  1.90  2.50  1.80  4.40  2.20  1.90  2.20  2.30  1.80  2.00  1.60
## [1549]  2.00  1.80  2.30  2.30  3.70  2.20  2.40  1.70  2.20  2.40  6.70  2.00
## [1561]  2.00  2.00  2.00  2.00  2.00  1.90  2.10  2.00  1.60  1.90  2.20  2.20
## [1573]  2.20  2.40 13.90  2.20  1.60  5.10  1.80  1.70  2.40  1.70  2.60  2.10
## [1585]  2.40  2.60  2.40  1.80  2.50  7.80  1.80  1.70  2.30  1.90  2.00  2.20
## [1597]  2.30  2.00  3.60
sd_sugar <- sd(`residual sugar`)
sd_sugar
## [1] 1.409928
var_sugar <- sd(`residual sugar`)/sqrt(length(`residual sugar`))
var_sugar
## [1] 0.03525922

The Central Limit Theorem (CLT) suggests a variability for the sample of residual sugar of 0.0353 (rounded to four decimal places).

# Lower confidence interval for residual sugar
lower_conf_sugar <- mu_sugar - 2*(var_sugar)
lower_conf_sugar
## [1] 2.468287

The lower confidence level for 95% confidence interval for the sample is 2.4683 (rounded to four decimal places).

# Upper confidence interval for residual sugar
upper_conf_sugar <- mu_sugar + 2*(var_sugar)
upper_conf_sugar
## [1] 2.609324

The upper confidence level for 95% confidence interval for the sample is 2.6093.

As evident above, we are able to use the CLT to give a 95% confidence interval for the sample of μ. The solution is: (2.4683, 2.6093).

(c) Use the bootstrap method to do part b. Is the bootstrap confidence interval symmetric? (hint: check the bootstrap distribution; see p. 75 in slides).

mu_sugar.set <- NULL
for (k in 1:2500) {
  sugar.bootstrap <- sample(`residual sugar`, size=1599, replace=T)
mu_sugar <- mean(sugar.bootstrap)
mu_sugar.set[k] <- mu_sugar
}

sd(mu_sugar.set)
## [1] 0.03587855

With the bootstrap method, the variability can be seen above. This is slightly greater than the variability when using the Central Limit Theorem; however, it is essentially equivalent.

conf_quantile_sugar <- quantile(mu_sugar.set, probs=c(0.025, 0.975))
conf_quantile_sugar
##     2.5%    97.5% 
## 2.469677 2.613077

The lower and upper confidence levels for 95% can be seen above (using the bootstrap method).

hist(mu_sugar.set, freq = FALSE)
lines(density(mu_sugar.set), lwd=5, col='blue')

From the above histogram, it is evident the boostrap confidence interval distribution is slightly skewed to the right, but mostly symmetric.

(d) Can we use a normal distribution to model “residual sugar”? If no, what distribution do you think can approximate empirical distribution? What parameters are needed to characterize such a distribution? What are their maximum likelihood estimates? Please provide their standard errors as well.

No, we cannot use a normal distribution to model “residual sugar”. The histogram of residual sugar is heavily skewed to the right. With that said, a lognormal distribution can be used to approximate empirical distribution. The Log Normal Distribution is described as, “Density, distribution function, quantile function and random generation for the log normal distribution whose logarithm has mean equal to meanlog and standard deviation equal to sdlog.”

The parameters μ and σ, or mean and standard deviation, are two parameters of the logarithm. dlnorm gives the density of the function, plnorm gives the distribution function, qlnorm gives the quantile function, and rlnorm generates random deviates.

minuslog.lik <- function(mu, sigma) {
  log.lik <- 0
  for(i in 1:1599) {
    log.lik = log.lik + log(dlnorm(x=`residual sugar`[i], meanlog=mu, sdlog=sigma))
  }
  return(-log.lik)
}

est_sugar <- mle(minuslog=minuslog.lik,
                 start = list(mu=log(mean(`residual sugar`)), sigma=log(sd(`residual sugar`))))

summary(est_sugar)
## Maximum likelihood estimation
## 
## Call:
## mle(minuslogl = minuslog.lik, start = list(mu = log(mean(`residual sugar`)), 
##     sigma = log(sd(`residual sugar`))))
## 
## Coefficients:
##        Estimate  Std. Error
## mu    0.8502341 0.008935942
## sigma 0.3573260 0.006318293
## 
## -2 log L: 3965.773

From the above function, the estimate for the mean is 0.8502 (rounded to four decimal places), and its standard error is 0.0089 (rounded to four decimal places). The estimate for the variability is 0.3573 (rounded to four decimal places), and its standard error is 0.0063 (rounded to four decimal places).

# Check the similarity
# Simulate 1599 observations from the fitted lognormal distribution using the MLEs as the parameter values

sugar.simulate <- rlnorm(1599, meanlog = 0.8502, sdlog = 0.3573)

par(mfrow = c(1, 2))
hist(sugar.simulate, breaks = seq(from = 0, to = 20, by = 1))
hist(`residual sugar`, breaks = seq(from = 0, to = 20, by = 1))

We classify those wines as “excellent” if their rating is at least 7. Suppose the population proportion of excellent wines is p. Do the following:

(a) Use the CLT to derive a 95% confidence interval for p;

First, a binary variable is created to be either one or zero; the value will be one if the wine’s rating is at least 7, and the value will be zero if the wine’s rating is less than 7.

The Bernoulli distribution will then be used. From the Lecture 2 notes, "The Bernoulli distribution models any data generating process that can be thought of as tossing a coin with a probability p of seeing the head. We say that a random variable X follows a Bernoulli distribution if:

# Create binary variable
red_wine$excellent <- as.numeric(red_wine$quality > 6)

# Sample proportion
p_hat <- mean(red_wine$excellent)
p_hat
## [1] 0.1357098
# Standard deviation of sample proportion
var_excellent <- sqrt(p_hat*(1 - p_hat) / length(red_wine$excellent))
var_excellent
## [1] 0.008564681
# Lower confidence interval for p
lower_conf_p <- p_hat - 2*(var_excellent)
lower_conf_p
## [1] 0.1185805

The lower confidence level for 95% confidence interval for p is 0.1186 (rounded to four decimal places).

# Upper confidence interval for p
upper_conf_p <- p_hat + 2*(var_excellent)
upper_conf_p
## [1] 0.1528392

The upper confidence level for 95% confidence interval for p is 0.1528 (rounded to four decimal places).

As evident above, we are able to use the CLT to give a 95% confidence interval for p. The solution is: (0.1186, 0.1528).

(b) Use the bootstrap method to derive a 95% confidence interval for p;

bootstrap_p.set <- NULL
for (k in 1:2500) {
  p.bootstrap <- sample(red_wine$excellent, size=1599, replace=T)
bootstrap_p <- mean(p.bootstrap)
bootstrap_p.set[k] <- bootstrap_p
}

sd(bootstrap_p.set)
## [1] 0.008679487
conf_quantile_p <- quantile(bootstrap_p.set, probs=c(0.025, 0.975))
conf_quantile_p
##      2.5%     97.5% 
## 0.1194497 0.1529237

The lower confidence level and the upper confidence level for 95% are seen above.

hist(bootstrap_p.set, freq = FALSE)
lines(density(bootstrap_p.set), lwd=5, col='blue')

(c) Compare the two intervals. Is there any difference worth our attention?

Using the CLT method, the interval is: (0.1186, 0.1528).
Using the bootstrap method, the interval is extremely similar. There is not any significant difference worth our attention.

(d) What is the maximum likelihood estimate of p and its standard error?

hist(red_wine$excellent)

# Bernoulli distribution
minuslog.lik <- function(p) {
  log.lik <- 0
  for(i in 1:1599) {
    log.lik <- log.lik + log(dbinom(red_wine$excellent[i], size = 1, prob = p))
  }
  return(-log.lik)
}

est <- stats4::mle(minuslog = minuslog.lik,
                   start = list(p = p_hat))

summary(est)
## Maximum likelihood estimation
## 
## Call:
## stats4::mle(minuslogl = minuslog.lik, start = list(p = p_hat))
## 
## Coefficients:
##    Estimate  Std. Error
## p 0.1357098 0.008564278
## 
## -2 log L: 1269.921
# Maximum likelihood estimation

Because the above histogram portrays a binary variable, the histogram only shows values of zero or one. From the above function, the estimate for the proportion of p is 0.1357 (rounded to four decimal places), and its standard error is 0.0086 (rounded to four decimal places).