DEV Community

maxwizard01
maxwizard01

Posted on • Edited on

How to measure dispersion using R.

How to measure the partition using R Questions and Answers.

As you would have learned in your statistic class, one of the most important part of statistics is measuring of partition.
Here we are going to deal with some university questions on the following

  1. Quartiles
  2. chebyshev
  3. epirical rule
  4. Standard Error and the Deviation

I believe you already understand the theoretical part and some little idea of how to write code to solve some of statistical problem. If you are new then I will advise you to some of my articles below this article.

Now let's move to the questions without wasting time.

Question1

Think of D = {20,21,20,23,34,45,45,43,23,29,30,43}. What is the standard error?

Solution.

we know that the formula for standard error is
StndErr=StandardDeviation/square root of N
whare N is the number of data.
so our code will look like the following.
** Code>>**

D=c(20,21,20,23,34,45,45,43,23,29,30,43)
D=sort(D)#this is to rearrange
stDev=sd(D) #to get the standard deviation
N=length(D) # to get the number of Data
StdErr=stDev/sqrt(N) # the formula
StdErr   #print the result
Enter fullscreen mode Exit fullscreen mode

Result>>

[1] 2.967841

Enter fullscreen mode Exit fullscreen mode

Question2

Simulate a sequence of number between 1 and 1000 with increment rate of 3. What is the [mean, standard deviation] value?

Solution

firstly we need to form sequence, then use the mean() and the sd() function to find the mean and standard deviation. the code is below.
Code>>

#question Number2
series=seq(1,1000,by=3)
Mean=mean(series)# get the mean
stDev=sd(series) # get standard deviation
Mean #print the result
stDev #print the result
Enter fullscreen mode Exit fullscreen mode

Result>>

[1] 500.5
[1] 289.6852
Enter fullscreen mode Exit fullscreen mode

Question3

Simulate a sequence of number between 1 and 1000 with increment rate of 3. What is the [mean, standard error] value?

Solution

this is just like question2 except that we need to find the standard error. Recall that standard error is the ratio of standard deviation to square-root of N. i.e StdErr=sd/sqrt(N).
so we write the following code to solve the question
Code>>>

#question Number2
series=seq(1,1000,by=3)
Mean=mean(series)# get the mean
stDev=sd(series) # get standard deviation
N=length(series) # to get the number of Data
StdErr=stDev/sqrt(N) # the formula
Mean #print the result for mean
StdErr   #print the result for Standard Error
Enter fullscreen mode Exit fullscreen mode

Result>>

> #question Number2
> series=seq(1,1000,by=3)
> Mean=mean(series)# get the mean
> stDev=sd(series) # get standard deviation
> N=length(series) # to get the number of Data
> StdErr=stDev/sqrt(N) # the formula
> Mean #print the result for mean
[1] 500.5
> StdErr   #print the result for Standard Error
[1] 15.85087
> 
Enter fullscreen mode Exit fullscreen mode

Question4

Simulate a sequence of number between 1 and 1000 with increment rate of 3. What is the coefficient of variation?
Solution
we know that the formula for the coefficient of variation is the ratio of standard Deviation to Mean i.e CV=S.D/Mean

Code>>

#Coefficient of variation
series=seq(1,1000,by=3)
Mean=mean(series) #calculate mean
stDev=sd(series) # calculate standard deviation
CV=stDev/Mean #the formular
CV #print Coefficient of standard deviation
Enter fullscreen mode Exit fullscreen mode

Result>>

[1] 0.5787916

Enter fullscreen mode Exit fullscreen mode

Question5

Given the following from the PUTME of student in UI {63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58}. Using Empirical rule , what is the interval of the distribution of PUTME scores, assume k = 1.5.

Solution

Here we know that using epirical rule interval= mean -or + K(standard Deviation)
so we need code to get standard deviation and the mean then we can write the formula. so the code is below:
Code>>

score=c(63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58)
score=sort(score)
stDev=sd(score)
Mean=mean(score)
K=1.5
Interval1=Mean-stDev*K # formular
Interval2=Mean+stDev*K
Interval1 #print the first interval
Interval2 #print the second interval
Enter fullscreen mode Exit fullscreen mode

Result>>


[1] 51.22629
[1] 73.67371

Enter fullscreen mode Exit fullscreen mode

Question6

Given the following from the PUTME of student in UI {63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58}. Using Chebyshev rule , how many data points lie within the distribution of PUTME scores, assume k = 1.5.

Solution
According to Chebyshev rule. the number of data point lies within a distribution is {1-(1/k^2)}x100%.

Code>>

score=c(63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58)
K=1.5
noOfData=(1-1/(K^2))*100 #formula
noOfData # print result
Enter fullscreen mode Exit fullscreen mode

Result>>

[1] 55.55556
Enter fullscreen mode Exit fullscreen mode

Question7

Given the following from the PUTME of student in UI {63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58}. What is the 3rd quartile?

Solution

You should know that Q3=3/4(N+1)th position after arranging the data in ascending order.
Code>>

score=c(63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58)
score=sort(score)
N=length(score)
position=3/4*(N+1)
Q3=score[position] # the position of Q3
# get the value in that position
Q3 #print the Q3
Enter fullscreen mode Exit fullscreen mode

Result>>

[1] 69
Enter fullscreen mode Exit fullscreen mode

There is another easy way to find the third quartile, that is using quantile () inbuilt function. Since third-quartile is the same as 75th percentile then we can find the third quartile with the following codes.

Code>>

score=c(63, 74, 53, 56, 50, 51, 72, 60, 63, 67, 68, 50, 70, 70, 59, 71, 63, 59, 56, 58, 64, 70, 54, 58, 74, 63, 54, 54, 51, 59, 74, 61, 64, 50, 69, 52, 55, 59, 59, 55, 64, 69, 69, 75, 61, 74, 72, 55, 74, 57, 61, 74, 72, 73, 55, 75, 56, 68, 59, 55, 73, 63, 51, 62, 67, 71, 63, 55, 50, 68, 68, 57, 55, 72, 61, 55, 57, 56, 60, 66, 53, 62, 57, 74, 65, 74, 72, 63, 69, 56, 62, 71, 61, 65, 50, 62, 70, 55, 66, 58)
Q3=quantile(score,0.75)
Q3 #print the Q3
Enter fullscreen mode Exit fullscreen mode

Result>>

[1] 69
Enter fullscreen mode Exit fullscreen mode

I believe you find the article interesting?? you can still chat me up on whatsApp(07045225718) or facebook if you have any question concerning this that you want ask or solved.You can also follow me on Instagram I am the guy Maxwizard!...Enjoy coding..
You can also read the following.

🔥 Introduction to R (1)

🔥 Data Structure (2)

🔥 Statistical value (mean, median, mode etc) (3)

🔥 Tabular Presentation of Data (4)

🔥 Ploting graph with R

🔥 constructing frequency distribution with R (6)

🔥 how to use R-programming to calculate Arithmetic,Geometric and Harmonic mean.

Top comments (0)