Statistics R Charts and Graphs Assignment
Statistics R Charts and Graphs Assignment
National University of Computer and Emerging Sciences - FAST
Computer Science Department
Question 1)
According to the Union of Concerned Scientists (www.ucsusa.org), as of November 2012, there
were 502 low Earth orbit (LEO) and 432 geosynchronous orbit (GEO) satellites in space. Each
satellite is owned by an entity in either the government, military, commercial, or civil sector. A
breakdown of the number of satellites in orbit for each sector is displayed in the accompanying
table. Use this information to construct pair of graphs (i. Rectangles, Pie Chart) that compare
the ownership sectors of LEO and GEO satellites in orbit. What observations do you have about
the data?
Solution)
1) Pie Chart
, Page 1
Probability and Statistics (Fall 2019) Assignment#1
2) Rectangle Chart
x <- c(229,109,118,46)
colours = rainbow(length(x)) # No. of items
Family <- c("LEO","GEO") # no of columns
type <- c("Government","Military", "Commercial", "Civil") # of items
y <- c(59,91,281,1)
rectanglePercent <- c(round(100*(x/sum(x)), 1))
rectanglePercent2 <- c(round(100*(y/sum(y)), 1))
Values <- matrix(c(rectanglePercent ,rectanglePercent2), nrow = 4, ncol = 2, byrow
= FALSE)
, Page 2
Probability and Statistics (Fall 2019) Assignment#1
width = sum(x):sum(y)
Question#2)
Do social robots walk or roll? According to the United Nations, social robots now outnumber industrial
robots worldwide. A social (or service) robot is designed to entertain, educate, and care for human users.
In a paper published by the International Conference on Social Robotics (Vol. 6414, 2010), design
engineers investigated the trend in the design of social robots. Using a random sample of 106 social
robots obtained through a web search, the engineers found that 63 were built with legs only, 20 with
wheels only, 8 with both legs and wheels, and 15 with neither legs nor wheels.
b. Identify the variable measured for each of the 106 robot designs.
c. Use graph to identify the social robot design that is currently used the most.
d. Compute class relative frequencies for the different categories shown in the graph.
, Page 3
Probability and Statistics (Fall 2019) Assignment#1
Solution)
a. Bar graph as one bar for each category is suitable for this type of data.
b. The variables for measurement are
i. Legs only
ii. Wheels only
iii. Both
iv. None
c. Graph R code
, Page 4
Probability and Statistics (Fall 2019) Assignment#1
None 0.14
Both 0.08
Question 3)
Use R Code to construct a pie chart to organize the data given in problem 2. What can you conclude?
Conclusion: The robots with legs only are used the most. On the other hand, very few robots
have both legs and wheels
, Page 5
Probability and Statistics (Fall 2019) Assignment#1
Question 4)
Component Bar Graph
Take a suitable data set to construct the component bar diagram through R-lang.
years = c(2015,2016,2017,2018)
current = c(14212521,20147852,24587598,39215389)
nonCurrent = c(25489584,30124578,61547896,106254875)
# converting to million dollars
current = current / 1000000
nonCurrent = nonCurrent / 1000000
colors = c("Red","Green")
barNames = c("Current Assets","Non-current Assets")
barplot(rbind(current,nonCurrent), width = .3, main = "Xiaomi Computers total
assets",names.arg = years, xlab = "Years", ylab = "Assets (Million Dollars)", col =
colors)
, Page 6
Probability and Statistics (Fall 2019) Assignment#1
years = c(2016,2017,2018)
smartPhones = c(12.4,45.3,102.5)
lifestyleProducts = c(11.4, 44.5, 67.4)
internetServices = c(9.2, 17.5, 45.5)
others = c(14.5, 19.7, 34.9)
colors = c("Red","Green","Yellow","Blue")
barNames = c("Smartphones","Lifestyle Products", "Internet Services", "Others");
barplot(rbind(smartPhones,lifestyleProducts,internetServices,others), width = .3,
beside = TRUE, main = "Xiaomi Computers total devices and services sold in past 3
years",names.arg = years, xlab = "Years", ylab = "No. of devices (in million)",
col = colors)
legend("topleft",barNames, cex = 1 , fill = colors)
, Page 7
Probability and Statistics (Fall 2019) Assignment#1
Question 5)
Collect the data (40-50 values) on a targeted variable which must be continuous:
(ii) List the mid-points for your frequency distribution, as well as the relative and cumulative
frequencies.
(iii)Draw a histogram depicting the data from the frequency table in # (ii) above and
(v) Show the histogram, density curve and frequency polygon in one graph.
(vi) Also construct an Ogive for the data considered before through R.
, Page 8
Probability and Statistics (Fall 2019) Assignment#1
table
MidPoints<-seq(mini+h/2,(maxi+h)-h/2,h)
MidPoints
cumulative_freq=cumsum(table)
cumulative_freq
RF = table/n
RF
# change column name of RF from "frequency" to "Relative Frequency"
colnames(RF)<- "Rel f"
finalTable = cbind ( frequency ,MidPoints,cumulative_freq,RF)
finalTable
Output
frequency MidPoints cumulative_freq Rel f
[34,43) 9 38.5 9 0
.18
[43,52) 20 47.5 29 0 .40
[52,61) 4 56.5 33 0 .08
[61,70) 6 65.5 39 0 .12
[70,79) 0 74.5 39 0 .00
[79,88) 5 83.5 44 0 .10
[88,97) 6 92.5 50 0 .12
iii) Frequency polygon superimposed on Histogram
data=c(94,68,66,68,62,67,67,89,88,88,88,88,86,86,84,84,83,5 3,52,51,51,57,57,49,49,
49,49,48,48,48,46,46,45,45,45,44,43,43,43,43,43,42,42,40,39,37,37,36,35,34)
, Page 9
Probability and Statistics (Fall 2019) Assignment#1
, Page 10
Probability and Statistics (Fall 2019) Assignment#1
, Page 11
Probability and Statistics (Fall 2019) Assignment#1
vi) Ogive.
data=c(94,68,66,68,62,67,67,89,88,88,88,88,86,86,84,84,83,53,52,51,51,57,57,49,49,49,4
9,48,48,48,46,46,45,45,45,44,43,43,43,43,43,42,42,40,39,37,37,36,35,34)
n<-length(data)
maxi<-max(data);
maxi
mini<-min(data);
mini
r<-(maxi-mini)
r
noOfClasses = ceiling(1+3.322*log10(length(data)))
noOfClasses
h<-ceiling(r/noOfClasses) # To find the width/size of class.
h
MidPoints<-seq(mini+h/2,(maxi+h)-h/2,h)
MidPoints
breaks = seq(mini,maxi+h,h)
dataCut = cut(data, breaks, right=FALSE)
frequency = table(dataCut)
midpoint0 = c(0,MidPoints)
cumuFreq = c(0, cumsum(frequency))
plot(midpoint0,cumuFreq,main="Ogive",xlab="Observations", ylab="Cumulative Frequency")
lines(midpoint0, cumuFreq,col="lightgreen",lwd=3,type="o")
, Page 12