Week7-solution
Week7-solution
July 2017
Solution to Assignment 7
1. The command table is used to generate frequency tables in R. The data should be in
vector form. Thus table(c(4,5,5,1,2,1,1,6,3,1)) is the correct command to obtain
the absolute frequencies of the given data in R.
Hence option a is correct.
2. The command table is used to generate frequency tables in R. The corresponding data
should be in vector form.
The output of the command
table(c(5,4,6,5,3,3,5,1,4,4,2,1,5,5,6,3,1,1,2,1,1))in R is
1 2 3 4 5 6
6 2 3 3 5 2
Hence option c is correct.
4. Since the probabilities are generated in a sequence from 0 to 1 as 0.0, 0.2, 0.4, 0.6, 0.8 and
1 by the commend probs = seq(0, 1, 0.20), so it provides the 0th, 20th, 40th, 60th,
80th, 100thquantiles.
1
5. The command
table(c(5,4,6,5,3,3,5,1,4,4,2,1,5,5,6,3,1,1,2,1,1))/length(c(5,4
,6,5,3,3,5,1,4,4,2,1,5,5,6,3,1,1,2,1,1))
will give the relative frequencies of the given data in tabular form. The command
barplot(table(c(5,4,6,5,3,3,5,1,4,4,2,1,5,5,6,3,1,1,2,1,1))/leng
th(c(5,4,6,5,3,3,5,1,4,4,2,1,5,5,6,3,1,1,2,1,1)))
is used to obtain the barplot of the given data in R based on relative frequencies.
6. The command hist command gives the histogram of the given data in R. The data should
be stored in a vector.
8. To calculate the mean of the non-missing values in the data, the command na.rm is used
inside the argument as mean(data,na.rm=TRUE) or mean(data,na.rm=T).
2
10. To calculate the product of the non-missing values in the data, the command
na.rmargument is used as prod(data,na.rm=TRUE) or prod(data,na.rm=T).
12. To calculate the median of the non-missing values in the data, the command na.rm
argument is used as median(data,na.rm=TRUE)or median(data,na.rm=T).
13. To calculate the variance of the non-missing values in the data, na.rm argument is used as
var(data,na.rm=TRUE)or var(data,na.rm=T). The standard deviation is defined
as the square root of the variance.
15. The command IQR command gives the interquartile range of the data.
IQR(c(14,15,NA,11,12,11,11,16,NA,12),na.rm=TRUE) is the correct
command to obtain the interquartile range of the given data in R.
3
16. This command abs first computes the absolute values of the data, then sum finds its
addition and then difference with the mean values of the data computes the mean absolute
deviation.
17. The command boxplot() command gives the boxplot of the given data. To obtain the
boxplot of the non-missing values in the data, na.rm is used inside the argument as
boxplot(data,na.rm=TRUE) or boxplot(data,na.rm=T).
18. The command skewness() function in the 'moments' package gives the coefficient of
skewness of the given data. To obtain the coefficient of skewness of the non-missing values in
the data, na.rm is used inside the argument as
skewness(data,na.rm=TRUE) or skewness(data,na.rm=T).
19. The command kurtosis() function in the 'moments' package gives the coefficient
ofkurtos is of the given data.
20. The command kurtosis() function in the 'moments' package gives the coefficient of
kurtosis of the given data. To obtain the coefficient of kurtosis of the non-missing values in the
data, na.rm is used inside the argument as
kurtosis(data,na.rm=TRUE)or kurtosis(data,na.rm=T).