In: Statistics and Probability
Built in Data In R:
This Question uses "cystfibr" data found in "ISwR" package. to access this data you need to first install "ISwR" package. then load the library. Type data() to check which built in data are in the package "ISwR". This should show all the available built in data as: We use nickel data for this part. Type >cystfibr to see the data, and then answer the following questions using the data: (a) type ?cystfibr this will open up a help file explaining about the 'cystfibr' data. What is cystfibr data about? (b) How many Males and how many Females are in the study? (c). Construct a bar diagram of the male and female. Change color to Red. {hint: barplot(table(sex))} (d.) Calculate the average height of the participants (e). Calculate the variance of the weight of the participants. (f). Calculate the Standard Deviation of the weight of the participants. (g). Construct a histogram of weight of the participants. (h). Construct a scattered plot height and weight [hint: plot(height, weight)]
R-commands and outputs:
# Install package
# Load package ISwR
library(ISwR)
(a)
?cystfibr
# Description: The cystfibr data frame has 25 rows and 10 columns.
It contains lung function data for cystic fibrosis patients (7–23
years old).
(b)
d=cysfibr
head(d)
# sex-a numeric vector code, 0: male, 1:female.
sum(d$sex) # This gives number of females
[1] 11
# On subtraction we obtain number of males(M), 25-11=14
# Number of males=14
# Number of females=11
(c)
# Bar diagram of male and female.
sex=d$sex
sex
[1] 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0
barplot(table(sex))
barplot(table(sex),xlab=c("0: Male","1: Female"),col=2)
(d)
# Average height of all the participants
height=d$height
mean(height)
[1] 152.8
(e)
# the variance of the weight of the participants
weight=d$weight
var(weight)
[1] 320.3429
(f)
# the Standard Deviation of the weight of the participants
sd(weight)
[1] 17.89813
(g)
# a histogram of weight of the participants.
hist(weight)
(h)
# a scattered plot height and weight
plot(height, weight, main="Scattered plot of height vs weight")
Screenshot: