In: Math
This question involves coding in RStudio Problem 3 (Verzani problem 2.22):
Write a function to compute the average distance from the mean for some data vector.
X=c(299.87,100.85,108.91,203.24,204.91,200.19,247.11,145.11,330.33,94.33,
127.96,117.64,109.11,114.79,186.3,210.07,125.62,302.74,185.36,280.55,548.58,
174.12,285.37,66.24,262.09,89.59,150.58,311.13,57.54,125.64,125.86)
# Mean of the variable X
Mean=mean(X)
Mean
## The distance of each value from that mean
Y=abs(Mean-X)
Y
## The mean of those distances
Mean_distance=mean(Y)
Mean_distance
############# RUN ###########
>
X=c(299.87,100.85,108.91,203.24,204.91,200.19,247.11,145.11,330.33,94.33,
+
127.96,117.64,109.11,114.79,186.3,210.07,125.62,302.74,185.36,280.55,548.58,
+
174.12,285.37,66.24,262.09,89.59,150.58,311.13,57.54,125.64,125.86)
>
> # Mean of the variable X
>
> Mean=mean(X)
> Mean
[1] 190.0558
>
> ## The distance of each value from that mean
>
> Y=abs(Mean-X)
> Y
[1] 109.814194 89.205806 81.145806 13.184194 14.854194
10.134194
[7] 57.054194 44.945806 140.274194 95.725806 62.095806
72.415806
[13] 80.945806 75.265806 3.755806 20.014194 64.435806
112.684194
[19] 4.695806 90.494194 358.524194 15.935806 95.314194
123.815806
[25] 72.034194 100.465806 39.475806 121.074194 132.515806
64.415806
[31] 64.195806
>
> ## The mean of those distances
>
> Mean_distance=mean(Y)
> Mean_distance
[1] 78.41642