1. GENERATE A RANDOM, NORMALLY DISTRIBUTED SAMPLE OF SIZE N = 1000 (MEAN = 50; STANDARD DEVIATION = 10. CALCULATE THE RANGE, 1ST QUARTILE, 3RD QUARTILE AND INTERQUARTILE RANGE OF THIS SAMPLE.
#GENERATING NORMAL DISTRIBUTED SAMPLES
Normal_Samples <- rnorm(1000, mean = 50, sd = 10)
Normal_Samples
##    [1] 46.93683 45.74551 46.34203 61.62234 47.68213 57.30181 54.13440 53.74047
##    [9] 54.23404 41.57876 61.40037 40.48014 54.24279 43.10627 51.67699 22.78028
##   [17] 37.41166 61.22474 41.93047 59.75376 40.23509 46.22559 43.39180 50.67033
##   [25] 44.53624 44.56690 38.88077 52.12808 62.93687 40.68492 48.42098 48.18900
##   [33] 33.30241 45.42217 54.86111 55.01979 46.99148 51.17789 45.38321 52.37112
##   [41] 48.87906 52.79059 35.80601 52.39583 64.68970 60.96866 31.15703 62.01263
##   [49] 47.84459 60.08740 55.30485 52.23908 52.18608 33.69496 39.67435 40.71089
##   [57] 53.00072 46.18741 54.92819 34.79433 42.46130 40.99923 50.05760 54.69132
##   [65] 70.99940 49.41346 45.02861 35.20614 41.51269 48.28341 49.13970 46.64242
##   [73] 44.44601 53.17950 54.26344 46.07254 58.15110 48.63902 54.66452 52.80884
##   [81] 49.03568 49.71786 50.15583 55.19875 52.50272 76.44528 49.92323 52.70635
##   [89] 34.60058 29.64163 40.88691 58.95552 59.93984 50.11313 66.07571 54.56483
##   [97] 46.66457 56.55823 64.22539 54.28550 51.42743 46.67739 55.73431 47.01600
##  [105] 51.00073 46.01657 28.13799 46.87169 55.58069 48.50260 43.39092 15.05225
##  [113] 45.79286 63.92401 60.26430 62.60464 51.32094 48.98186 65.32746 44.64990
##  [121] 49.44508 41.96462 46.95535 49.30648 47.11970 47.26536 64.15564 57.22953
##  [129] 55.29223 48.80329 61.87971 51.14993 60.58245 39.98245 47.59943 67.61646
##  [137] 43.43111 50.03998 57.60083 41.78362 47.48889 52.66848 50.70433 41.31962
##  [145] 65.12911 53.40217 37.93308 47.68151 53.90795 24.94531 54.91004 41.33836
##  [153] 57.28255 51.37214 48.33595 55.59962 48.37625 45.49965 40.30703 38.46072
##  [161] 52.73918 57.60901 40.40598 51.97802 54.78857 43.05140 46.87563 50.10070
##  [169] 65.44551 37.92932 52.65564 43.01993 43.08797 46.80943 52.86679 58.38862
##  [177] 31.03365 68.50191 58.72996 59.73765 46.52473 67.84645 35.39719 52.95342
##  [185] 70.19940 63.89016 59.18003 51.04869 40.18954 51.16245 56.99767 46.88799
##  [193] 69.69266 40.30046 54.57518 47.51270 50.49058 49.63242 55.47612 46.92868
##  [201] 43.63850 51.10148 37.19500 55.11654 61.16157 44.78328 45.07427 62.29786
##  [209] 55.95568 50.60872 49.41633 51.25980 43.60179 36.19950 58.02017 50.25820
##  [217] 49.27652 63.95317 47.01159 54.30461 53.27600 49.17533 45.47204 43.65611
##  [225] 70.81705 52.66202 26.55086 72.09403 52.79685 59.24035 56.14378 46.58956
##  [233] 33.70596 72.90834 37.23752 42.32615 59.65222 68.81549 45.09462 43.13692
##  [241] 37.55174 42.63730 44.35329 62.05738 51.11500 59.85907 61.08589 52.54091
##  [249] 66.23667 55.64295 64.55155 52.34867 46.86289 52.73383 60.57201 57.72695
##  [257] 66.08651 51.19161 61.55581 47.27739 34.27803 54.16665 53.24074 39.25654
##  [265] 56.99591 51.38669 45.16611 62.98017 55.94051 40.95591 37.11290 47.27156
##  [273] 50.46847 40.64130 53.28098 48.68021 33.09344 60.29927 40.89730 68.38694
##  [281] 35.26993 60.31960 50.57121 65.87076 51.87646 51.30735 50.17104 43.71061
##  [289] 44.08091 69.62161 56.68335 63.50750 48.15626 54.11153 44.30827 40.95464
##  [297] 47.10276 63.36862 69.45136 81.14564 44.93948 52.60257 42.97104 32.72320
##  [305] 62.92263 57.61233 24.88879 42.15852 41.97661 48.28418 44.15237 54.90774
##  [313] 79.43583 53.25308 51.64096 67.96391 52.06061 37.89654 41.49616 29.88015
##  [321] 56.77538 56.37333 44.08572 49.30973 48.72645 58.07990 44.45051 41.70896
##  [329] 53.28505 55.11094 64.56748 42.07409 53.67515 51.03143 40.79942 35.95130
##  [337] 65.76680 41.14020 37.93562 31.00666 57.01624 43.24278 52.93959 40.69372
##  [345] 47.00935 61.02286 47.25958 50.02807 60.48969 63.90560 35.39064 55.88061
##  [353] 45.45723 47.97076 64.04110 52.59985 33.80593 54.45996 59.65094 61.04595
##  [361] 54.15496 54.34686 35.99366 45.92045 49.44519 64.39762 36.28515 40.35702
##  [369] 30.69288 51.93977 51.18193 42.76815 47.81351 51.81851 43.34390 41.78765
##  [377] 47.02629 61.93914 36.94519 71.75401 46.36347 51.22842 63.14286 41.63681
##  [385] 41.75448 62.16403 54.21482 72.43698 67.87814 45.90267 42.01002 58.35749
##  [393] 41.99772 55.14655 42.29975 53.82326 40.51645 54.20706 30.13487 39.99678
##  [401] 35.48868 66.76945 44.10398 46.31761 53.22695 59.69288 69.10229 54.04205
##  [409] 58.76808 56.30747 49.21397 43.65328 49.26099 32.07179 39.56880 32.75056
##  [417] 36.20460 41.47815 36.96430 61.10676 50.43206 51.85379 43.48339 46.24836
##  [425] 47.92721 41.97197 55.10996 50.58868 42.00426 46.12443 49.68574 33.80728
##  [433] 54.25022 58.91543 62.37837 55.15701 44.76310 72.67213 52.82673 49.40835
##  [441] 48.99276 37.38792 44.08404 59.12052 42.62030 53.20832 38.55446 40.51918
##  [449] 53.40677 65.05387 47.77136 40.64820 58.35554 54.60940 44.57714 45.28136
##  [457] 49.96644 46.39081 69.92436 49.04019 52.76383 65.95429 51.29687 67.21600
##  [465] 46.93692 59.70592 42.84555 46.13159 49.29927 49.79010 54.59692 62.41248
##  [473] 38.04272 54.87397 56.69422 42.46172 48.94510 43.51597 57.56285 66.66618
##  [481] 62.16464 57.47322 46.74345 62.43764 31.66071 50.79788 56.07791 58.84792
##  [489] 53.95245 48.55466 59.36281 54.44927 50.29940 61.63378 55.29071 52.33822
##  [497] 37.85060 39.53006 56.24443 20.41278 34.40205 62.10555 14.06137 35.23882
##  [505] 70.44512 47.96997 52.24494 46.89231 54.46699 47.89560 52.02525 30.92853
##  [513] 53.01107 31.37562 46.65070 63.89902 47.15385 54.28015 48.18840 51.21212
##  [521] 51.77297 57.65899 51.03633 52.50603 56.99735 52.98482 59.24268 67.97164
##  [529] 55.78424 54.84302 52.31622 42.61565 47.73756 43.98190 72.32045 45.32029
##  [537] 52.58348 50.35427 75.12129 58.90883 49.98553 55.90479 38.57578 59.74466
##  [545] 39.96639 34.42181 54.27445 40.33807 45.68056 43.50908 59.94442 56.79879
##  [553] 60.85896 46.49204 51.37176 62.13099 56.03258 56.19011 61.33952 63.23971
##  [561] 24.61463 39.02362 49.02830 65.71504 61.92221 50.14403 38.74203 51.07305
##  [569] 27.91729 54.50400 65.73437 56.45397 64.00945 61.02791 40.37483 38.63708
##  [577] 59.20293 35.15663 34.41065 52.34398 41.13150 42.16230 28.58657 46.00893
##  [585] 44.05600 66.01438 46.98505 53.63956 51.05556 56.85021 36.63915 44.31568
##  [593] 45.65095 56.90047 56.72422 36.12252 55.18595 49.33522 59.02760 61.78824
##  [601] 44.38406 53.22042 25.32905 47.87479 42.87759 59.42986 33.85173 53.27183
##  [609] 60.95329 54.49276 48.29977 70.97655 49.30065 67.22172 40.79848 62.23279
##  [617] 27.47712 72.32931 49.13173 38.37689 66.25659 51.99259 50.61078 44.91609
##  [625] 61.07599 43.52105 79.88042 55.24840 54.60780 43.83278 47.33199 52.20849
##  [633] 50.62648 59.02317 47.60713 41.94079 54.92160 41.11762 43.27318 52.96623
##  [641] 60.99023 54.94281 62.62901 47.06123 25.82378 31.04304 45.83285 68.51762
##  [649] 60.73162 43.20782 50.93112 52.30313 49.56450 65.04677 45.81499 62.82038
##  [657] 40.14813 56.14040 50.37716 53.88141 44.41797 62.05169 61.70746 57.90155
##  [665] 40.02514 53.15711 66.97119 40.37526 52.90996 46.56596 45.37720 43.19964
##  [673] 47.08929 32.88145 51.53964 36.03058 60.76807 50.49048 79.43362 58.82873
##  [681] 42.63810 51.35077 57.36414 22.57297 36.18255 52.14630 45.09441 43.22744
##  [689] 51.33587 60.20018 20.89718 54.62681 65.68883 49.47809 40.06034 50.76477
##  [697] 64.51821 47.09431 52.99370 61.80614 49.66095 51.80631 50.56452 42.58857
##  [705] 42.37480 40.59118 57.08448 51.03529 38.97160 43.57101 26.48888 52.98475
##  [713] 55.88527 62.13549 44.80470 47.23225 40.96074 37.62791 40.64959 54.38036
##  [721] 59.33369 49.40626 49.03015 68.97705 59.72270 61.39192 53.91241 39.55347
##  [729] 52.81910 41.93792 38.99732 49.61856 53.30320 54.99641 48.88898 27.10514
##  [737] 64.97535 53.95929 49.27409 55.55609 44.44763 54.20466 62.86365 53.78728
##  [745] 64.68213 58.25412 54.76630 49.95554 41.47596 52.73067 51.30084 51.76724
##  [753] 43.23745 27.17108 49.84389 45.48038 64.67823 52.35093 50.95091 45.11906
##  [761] 63.84119 50.20159 52.37593 50.76972 46.00476 59.06066 37.65076 42.76279
##  [769] 59.89551 57.43876 59.23581 30.56679 65.78130 46.21604 52.00279 75.93190
##  [777] 59.38687 52.41459 41.55832 64.14878 40.79989 55.46925 57.36767 48.27770
##  [785] 56.95710 46.77479 56.21674 52.60465 37.56659 47.87452 56.38948 53.55635
##  [793] 56.92679 41.13756 37.43991 61.49740 24.85999 41.91411 58.01164 56.91528
##  [801] 36.93247 27.07605 34.45854 69.43917 42.13333 43.12426 42.59564 27.91297
##  [809] 62.41495 49.28571 48.10495 58.18997 32.48164 63.04497 38.29599 50.97834
##  [817] 56.57355 53.05448 48.80240 55.57153 40.14734 61.73569 48.68323 32.24190
##  [825] 48.21567 41.89784 42.44571 46.59778 56.15838 40.70325 62.55774 55.48818
##  [833] 56.41038 42.79110 62.66327 65.78035 48.40537 58.83029 41.64183 62.24032
##  [841] 51.44351 55.21377 64.21564 70.72558 55.23488 48.88580 44.01055 36.99971
##  [849] 53.72748 65.40141 57.83481 50.40603 41.77041 66.67654 46.78123 54.23186
##  [857] 44.75181 54.25506 50.51719 50.91585 47.51292 49.38219 32.62578 70.02319
##  [865] 40.75846 51.57643 63.93046 34.78948 51.54002 65.14392 51.99647 42.26750
##  [873] 51.92873 38.72486 36.80091 47.32500 50.15107 51.06157 23.78235 53.34561
##  [881] 36.35514 54.09772 56.14660 40.12487 51.66957 55.82774 41.49830 56.75025
##  [889] 41.80484 45.23990 46.58841 28.39578 43.40352 49.74267 52.16619 60.84187
##  [897] 34.03867 65.78467 65.33546 35.21238 59.52115 42.17423 54.52237 59.24708
##  [905] 43.66542 56.22830 57.86718 38.99209 38.45326 49.63116 23.42450 54.88829
##  [913] 60.78545 48.12993 53.09169 62.82833 54.34698 43.58765 47.51232 41.09138
##  [921] 45.86331 62.91015 38.53829 48.06567 66.37288 59.48694 55.21482 49.65420
##  [929] 60.58833 55.63942 76.79394 45.12792 42.76573 52.94434 47.14673 57.17203
##  [937] 33.08583 42.67171 48.21180 53.43076 49.71863 55.53019 44.45838 31.70255
##  [945] 52.19653 37.55295 56.11461 62.35675 38.22742 69.16818 56.80282 81.07723
##  [953] 50.67660 46.84265 64.22614 50.46868 58.32054 51.14705 59.60456 48.57503
##  [961] 37.40255 56.15282 46.12436 51.98425 52.81534 45.52626 56.82317 31.79203
##  [969] 48.59047 54.19185 36.27945 49.24742 51.92312 54.54703 45.05389 65.84642
##  [977] 50.77731 50.02400 62.10573 58.15997 41.43489 55.89426 70.89914 60.00073
##  [985] 54.77812 36.30957 50.60049 55.16177 52.00412 53.59562 52.12610 57.89980
##  [993] 50.77742 64.43264 42.84635 42.52789 42.03617 46.64968 60.21107 59.70316
Normal_Samples.df<- data.frame(Normal_Samples)

#CONFIRMING NORMAL DISTRIBUTION
hist(Normal_Samples, breaks = 50, xlab = "Sample Value", main = "Sample's Frequency")

#RANGE CALCULATION, 1ST QUARTILE, 3RD QUARTILE, AND INTERQUARTILE (MEDIAN)
Range_Vector <- range(Normal_Samples.df)
min <- Range_Vector[1]
min
## [1] 14.06137
max <- Range_Vector[2]
max
## [1] 81.14564
Range <- (max - min)
Range
## [1] 67.08428
#1ST QUARTILE

Quantiles_1 <- quantile(Normal_Samples,0.25)
Quantiles_1
##      25% 
## 43.55852
#3RD QUARTILE
Quantiles_3 <- quantile(Normal_Samples, 0.75)
Quantiles_3
##      75% 
## 56.73073
#INTERQUARTILE
IQR(Normal_Samples)
## [1] 13.17221

2. USING THE FOLLOWING DATA: 29, 35, 17, 30, 231, 6, 27, 35, 23, 29, 13, FIND THE MEAN, MEDIAN AND RANGE.

#VECTOR CREATION

vector_point_2 <- c(29, 35, 17, 30, 231, 6, 27, 35, 23, 29, 13)

#MEAN
mean_vec_2 <- mean(vector_point_2)
mean_vec_2
## [1] 43.18182
#MEDIAN
median_vec_2 <- median(vector_point_2)
median_vec_2
## [1] 29
#RANGE
range_vec_2 <- max(vector_point_2) - min(vector_point_2)
range_vec_2
## [1] 225

3. FIND THE GROUPED MEAN OF THE FOLLOWING DATA:

CATEGORY FREQUENCY
<20 5
20 - 39.99 15
40 - 59.99 10
60 - 79.99 12
#VECTORS
Frequency <- c(5,15,10,12)
mid_point <- c(10,30,50,70)

#MATRIX CREATION

Point_3_Matrix <- matrix(c( Frequency, mid_point),nrow = 4, byrow = FALSE)

#LABELS CREATION
Column_Labels <- c( "Frequency", "Mid-Point")
Category_Labels<- c("<20", "20-39.99", "40-59.99", "60-79.99")

#LABELING
colnames(Point_3_Matrix) <- Column_Labels
rownames(Point_3_Matrix) <- Category_Labels
Point_3_Matrix
##          Frequency Mid-Point
## <20              5        10
## 20-39.99        15        30
## 40-59.99        10        50
## 60-79.99        12        70
#GROUPED MEAN LOOP
sum_freq_mid <- 0
sum_freq <-0
for (i in 1:nrow(Point_3_Matrix)) {
  sum_freq_mid <- sum_freq_mid + (Point_3_Matrix[i,1] * Point_3_Matrix[i,2])
  sum_freq <- sum_freq + (Point_3_Matrix[i,1])
}

grouped_mean <- sum_freq_mid/sum_freq
grouped_mean
## [1] 43.80952

4. TEN MIGRATION DISTANCES CORRESPONDING TO THE DISTANCES MOVED BY RECENT MIGRANTS ARE OBSERVED (IN KM): 43, 6, 7, 11, 122, 41, 21, 17, 1, 3. FIND THE MEAN AND STANDARD DEVIATION. INTERPRET THE RESULT IN YOUR OWN WORDS.

#MIGRATION DISTANCES VECTOR
migration_distances <- c(43, 6, 7, 11, 122, 41, 21, 17, 1, 3)

#MEAN
mean(migration_distances)
## [1] 27.2
#SD
sd(migration_distances)
## [1] 36.45637

The mean is an important statistical value that can give us an initial idea of how the data is distributed. However, the mean can be misleading and may not accurately represent the distribution of the data when there is high variability present. In these cases, the median is often used as a better statistical representation of the data’s distribution. Moreover, it is important to calculate the standard deviation to complement the mean analysis. In this case, we obtained a mean of 27.2 and a standard deviation of 36.45. We can observe some outliers such as 122, 43, and 41, which have influenced the mean, and as a result, the standard deviation is high.

5. CALCULATE DESCRIPTIVE STATISTICS OF INTELLIGENCE SCORES AS DESCRIBED IN THE FILE.

#DATA
Intelligence_Scores <- read.table("file:///C:/Users/fcam_/Downloads/Data_Point5.csv", header=TRUE,sep=";", dec = ",")
Intelligence_Scores <- Intelligence_Scores$X_i
Intelligence_Scores
##  [1]  96.8  95.9  92.6  98.7 106.4 124.5 107.1  58.1 101.8  96.0 102.6  64.8
## [13] 117.3 104.4  98.4 126.0 115.3  91.3  99.9 115.0
#ARITHMETIC MEAN
mean(Intelligence_Scores)
## [1] 100.645
#MEDIAN
median(Intelligence_Scores)
## [1] 100.85
#1ST QUARTILE
q1 <- quantile(Intelligence_Scores, 0.25)
q1
##    25% 
## 95.975
#2ND QUARTILE
q2 <- quantile(Intelligence_Scores, 0.5)
q2
##    50% 
## 100.85
#3RD QUARTILE
q3 <- quantile(Intelligence_Scores, 0.75)
q3
##     75% 
## 109.075
#INTER-QUARTILE RANGE
IQR(Intelligence_Scores)
## [1] 13.1
#MINIMUM
min(Intelligence_Scores)
## [1] 58.1
#MAXIMUM
max(Intelligence_Scores)
## [1] 126
#VARIANCE
var(Intelligence_Scores)
## [1] 279.971
#STANDARD DEVIATION
sd(Intelligence_Scores)
## [1] 16.73233

6. DESCRIBE THE FOLLOWING DATA BY USING COMMON DATA CATEGORIES (NOMINAL, ORDINAL, DICHOTOMOUS, DISCRETE, ETC.):

DATA CATEGORIES
INTELLIGENCE SCORE ORDINAL SCALE
TEMPERATURE IN KELVIN PROPORTIONAL SCALE
TEMPERATURE IN °C INTERVAL SCALE
RAINY DAYS IN SEPTEMBER DISCRETE DATA
HAIR COLOR (BLOND, BLACK, BROWN) NOMINAL SCALE
RANKING OF TEAMS IN A TOURNAMENT ORDINAL SCALE
BODY SIZE CLASSIFIED AS TINY, SMALL, MEDIUM, TALL AND GIANT NOMINAL SCALE
CUSTOMER SATISFACTION (SATISFIED OR NOT SATISFIED) DISCHOTOMOUS DATA

7. USING THE FOLLOWING DATA:

CITY X Y POPULATION
A 3.3 4.3 34000
B 1.1 3.4 6500
C 5.5 1.2 8000
D 3.7 2.4 5000
E 1.1 1.1 1500

A. FIND THE WEIGHTED MEAN CENTER OF POPULATION.

#MATRIX CREATION

x_coordinate <- c(3.3, 1.1, 5.5, 3.7, 1.1)
y_coordinate <- c(4.3, 3.4, 1.2, 2.4, 1.1)
Population <- c(34000, 6500, 8000, 5000, 1500)
columns_names <- c("X", "Y", "Population")
rows_labels <- c("A", "B", "C", "D", "E")

Point_7_Matrix <- matrix(c(x_coordinate, y_coordinate, Population),nrow = 5, byrow = FALSE)

colnames(Point_7_Matrix) <- columns_names 
rownames(Point_7_Matrix) <- rows_labels
Point_7_Matrix
##     X   Y Population
## A 3.3 4.3      34000
## B 1.1 3.4       6500
## C 5.5 1.2       8000
## D 3.7 2.4       5000
## E 1.1 1.1       1500
#DATAFRAME CREATION
Point_7_Matrix.df <- data.frame(Point_7_Matrix)

#VARIABLES CREATION
weighted_x <- 0
weighted_y <- 0
sum_population <- 0

#WEIGHTED MEAN CENTER LOOP
for (i in 1:nrow(Point_7_Matrix)) {
  weighted_x <- weighted_x + (Point_7_Matrix[i,3] *Point_7_Matrix[i,1] ) 
  weighted_y <- weighted_y + (Point_7_Matrix[i,3] *Point_7_Matrix[i,2] )
  sum_population <- sum_population + Point_7_Matrix[i,3]

}

weighted_mean_center = c(weighted_x/sum_population, weighted_y/sum_population)
weighted_mean_center
## [1] 3.336364 3.482727
wmc.df<- rbind((Point_7_Matrix.df), c(weighted_mean_center,0))

#VISUALIZING WEIGHTED MEAN CENTER

rows_labels <- row.names(wmc.df)
rows_labels[rows_labels == "6"] <- "F"
rownames(wmc.df) <- rows_labels


plot(wmc.df$Y ~ wmc.df$X, 
     xlab = "X Coordinate", ylab = "Y Coordinate", main = "Weighted Mean Center of Population")

points(x = wmc.df$X[6], y = wmc.df$Y[6], col = "red")
text(x = wmc.df$X, y = wmc.df$Y, labels = rows_labels, pos = 3)
text(x = wmc.df$X[1], y = wmc.df$Y[1], labels = rows_labels[1], pos = 2)
text(x = wmc.df$X[6], y = wmc.df$Y[6], labels = "WMC", pos = 1)

B. FIND THE UNWEIGHTED MEAN CENTER, AND COMMENT ON THE DIFFERENCES BETWEEN YOUR TWO ANSWERS.

#VARIABLES CREATION
sum_unweighted_x <- 0
sum_unweighted_y <- 0
num_cities <- nrow(Point_7_Matrix.df)

#UNWEIGHTED MEAN CENTER LOOP
for (i in 1:nrow(Point_7_Matrix.df)) {
  sum_unweighted_x <- sum_unweighted_x + (Point_7_Matrix[i,1])
  sum_unweighted_y <- sum_unweighted_y + (Point_7_Matrix[i,2])

}
unweighted_mean_center = c(sum_unweighted_x/num_cities, sum_unweighted_y/num_cities)
unweighted_mean_center
## [1] 2.94 2.48
unwmc.df<- rbind((Point_7_Matrix.df), c(unweighted_mean_center,0))

#VISUALIZING UNWEIGHTED MEAN CENTER
rows_labels <- row.names(unwmc.df)
rows_labels[rows_labels == "6"] <- "F"
rownames(unwmc.df) <- rows_labels


plot(unwmc.df$Y ~ unwmc.df$X, 
     xlab = "X Coordinate", ylab = "Y Coordinate", main = "Unweighted Mean Center of Population")

points(x = unwmc.df$X[6], y = unwmc.df$Y[6], col = "red")
text(x = unwmc.df$X, y = unwmc.df$Y, labels = rows_labels, pos = 3)
text(x = unwmc.df$X[1], y = unwmc.df$Y[1], labels = rows_labels[1], pos = 2)
text(x = unwmc.df$X[6], y = unwmc.df$Y[6], labels = "UNWMC", pos = 1)

Based on the data provided, the resulting Weighted Mean Center was 3.3363, 3.4827, while the resulting Unweighted Mean Center was 2.94, 2.48. After plotting all the city coordinates and both calculated Mean Centers, we can see that the Weighted Mean Center was influenced, as expected, by City “A”, as it has the highest population. As a result, the mean center is located near this city. On the other hand, the Unweighted Mean Center is not influenced by population, and its location is based solely on the mean of the city locations. This exercise demonstrates not only the influence of weighted values but also the importance of graphing the data to better understand and visualize it through exploratory data analysis (EDA).

C. FIND THE DISTANCE OF EACH CITY TO THE WEIGHTED MEAN CENTER OF POPULATION.

#DISTANCE MATRIX CREATION
distances_to_wmc <- 0
distance_to_wmc <- matrix(nrow = 0, ncol = 1,byrow = TRUE)

#DISTANCE CALCULATION LOOP

for (i in 1:nrow(Point_7_Matrix.df)) {
  distance<- sqrt(((weighted_mean_center[1] - Point_7_Matrix.df$X[i])^2) + (weighted_mean_center[2] - Point_7_Matrix.df$Y[i])^2)
  distance_to_wmc <- rbind(distance_to_wmc, distance)
  
}
distance_to_wmc[]
##               [,1]
## distance 0.8180813
## distance 2.2378932
## distance 3.1451814
## distance 1.1421601
## distance 3.2678298

D. FIND THE STANDARD DISTANCE (WEIGHTED) FOR THE FIVE CITIES.

#VARIABLES CREATION

SDW_distance <- 0
num_x <- 0
den_x <- sum(Point_7_Matrix.df$Population)

#WEIGHTED STANDARD DISTANCE LOOP
for (i in 1:nrow(Point_7_Matrix.df)) {
  num_x <- num_x + Point_7_Matrix.df$Population[i]*(distance_to_wmc[i])^2
  
}

SDW_distance <- sqrt((num_x/den_x))
SDW_distance
## [1] 1.689464

E. FIND THE RELATIVE STANDARD DISTANCE BY USING THE STANDARD DISTANCE IN PART (D), AND BY ASSUMING THAT THE STUDY AREA HAS A SIZE OF 10 (LOOK UP THE EQUATION FOR THE AREA OF A CIRCLE ONLINE TO CALCULATE R!).

#CALCULATING RADIUS
area <- 10
r = sqrt(area/pi) 

#RELATIVE STANDARD DISTANCE CALCULATION
relative_distance = SDW_distance/r
relative_distance
## [1] 0.9469431

F. REPEAT PART (E), THIS TIME ASSUMING THAT THE SIZE OF THE STUDY AREA IS 15.

#CALCULATING RADIUS
area <- 15
r = sqrt(area/pi) 

#RELATIVE STANDARD DISTANCE CALCULATION
relative_distance = SDW_distance/r
relative_distance
## [1] 0.7731758