40203478_Assignment_3
pdf
keyboard_arrow_up
School
Concordia University *
*We aren’t endorsed by this school
Course
280
Subject
Statistics
Date
Jan 9, 2024
Type
Pages
8
Uploaded by DeaconSalamander3940
Introduction to Statistical Programming: Assignment 3
Marissa Gonçalves (Student ID: 40203478)
Textbook Problems
Section 2.7 on Page 34
Problem 1
a)
# Create a vector containing solar radiation observation data, then display the values
# from the vector sample.
solar.radiation
<-
c(
11.1
,
10.6
,
6.3
,
8.8
,
10.7
,
11.2
,
8.9
,
12.2
)
solar.radiation
## [1] 11.1 10.6
6.3
8.8 10.7 11.2
8.9 12.2
b)
# Determine the mean, median, range and variance for solar radiation observations by
# utilizing appropriate functions.
mean(solar.radiation)
## [1] 9.975
median(solar.radiation)
## [1] 10.65
range(solar.radiation)
## [1]
6.3 12.2
var(solar.radiation)
## [1] 3.525
c)
The mean, median and range values for sr10 increased by 10, but the variance remains the same as the
variance value obtained from solar.radiation data.
# Create a variable sr10, which includes all solar radiation observation values added
# by 10, then use the mean, median, range and variance functions to calculate needed
# values for comparison.
sr10
<-
solar.radiation +
10
mean(sr10)
## [1] 19.975
median(sr10)
## [1] 20.65
range(sr10)
## [1] 16.3 22.2
1
var(sr10)
## [1] 3.525
d)
All mean, median, range and variance values for srm2 differ from solar.radiation data values.
# Create a variable srm2, which includes all solar radiation observation values
# multiplied by -2, then use the mean, median, range and variance functions to
# calculate needed values for comparison.
srm2
<-
solar.radiation * (-
2
)
mean(srm2)
## [1] -19.95
median(srm2)
## [1] -21.3
range(srm2)
## [1] -24.4 -12.6
var(srm2)
## [1] 14.1
e)
# Create three histograms with appropriate titles and unique colour codes to compare
# data stored in solar.radiation, sr10, srm2 variables with one another.
par(
mfrow=
c(
1
,
3
))
hist(solar.radiation,
main=
"Solar Radiation Graph I"
,
col=
"blue"
,
ylab=
"Number of Solar Radiation Observations"
,
xlab=
"Solar Radiation Values"
)
hist(sr10,
main=
"Solar Radiation Graph II"
,
col=
"gold"
,
ylab=
"Number of Solar Radiation Observations"
,
xlab=
"Solar Radiation Values Added by 10"
)
hist(srm2,
main=
"Solar Radiation Graph III"
,
col=
"purple"
,
ylab=
"Number of Solar Radiation Observations"
,
xlab=
"Solar Radiation Values Multiplied by -2"
)
2
Solar Radiation Graph I
Solar Radiation Values
Number of Solar Radiation Observations
6
8
10
12
14
0
1
2
3
4
Solar Radiation Graph II
Solar Radiation Values Added by 10
Number of Solar Radiation Observations
16
18
20
22
24
0
1
2
3
4
Solar Radiation Graph III
Solar Radiation Values Multiplied by -2
Number of Solar Radiation Observations
-25
-20
-15
-10
0
1
2
3
4
5
Problem 3
# Create variable n as a sequence from 1 to 15, then determine the pairwise maxima
# between both 2ˆn and nˆ3, before summing the pairwise value using the function pmax().
n
<-
1
:
15
sum(pmax(
2
ˆn, nˆ
3
))
## [1] 66538
Section 2.9 on Page 46
Problem 2
a)
# Utilize the nrow() function to determine the number of rows and the ncol() function
# to find the number of columns in the USArrests data frame. According to the results,
# there are 50 rows and 4 columns in USArrests built-in data frame.
nrow(USArrests)
## [1] 50
ncol(USArrests)
## [1] 4
b)
# Utilize the vapply() function to determine the median of each column in the USArrests
# data frame.
vapply(USArrests, median,
1
)
3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
##
Murder
Assault UrbanPop
Rape
##
7.25
159.00
66.00
20.10
c)
When the population in urban areas exceeds 77%, the average per capita murder rate is greater by 0.25
compared to when the urban area population is less than 50%.
# Utilize the mean() function to determine the average per capita murder rate when the
# USArrests data frame urban area population is more than 77%.
average.greater.than
.77
<-
mean(USArrests$Murder[USArrests$UrbanPop >
77
])
average.greater.than
.77
## [1] 8.5
# Then, use the same strategy to determine the average per capita murder rate when the
# USArrests data frame urban area population is less than 50%.
average.less.than
.50
<-
mean(USArrests$Murder[USArrests$UrbanPop <
50
])
average.less.than
.50
## [1] 8.25
d)
# Utilize the sample() function to retrieve 12 elements without replacement from the
# USArrests data frame containing 50 records and the data.frame() function to construct
# a new data frame for the newly-created sample.
sample.id
<-
sample(
1
:
50
,
size =
12
,
replace =
FALSE)
records.sample
<-
data.frame(USArrests[sample.id, ])
records.sample
##
Murder Assault UrbanPop Rape
## Kansas
6.0
115
66 18.0
## Arizona
8.1
294
80 31.0
## South Carolina
14.4
279
48 22.5
## New York
11.1
254
86 26.1
## Oklahoma
6.6
151
68 20.0
## Tennessee
13.2
188
59 26.9
## Florida
15.4
335
80 31.9
## Mississippi
16.1
259
44 17.1
## Idaho
2.6
120
54 14.2
## California
9.0
276
91 40.6
## Oregon
4.9
159
67 29.3
## Alaska
10.0
263
48 44.5
Chapter 2 Exercises on Page 50 and 51
Problem 3
a)
# Use the subset() function to construct a subset of the chickwts data frame where the
# weight of chicks is greater than 300.
chickwts300p
<-
subset(chickwts, weight >
300
)
chickwts300p
##
weight
feed
## 11
309
linseed
## 26
327
soybean
## 27
329
soybean
## 31
316
soybean
4
## 37
423 sunflower
## 38
340 sunflower
## 39
392 sunflower
## 40
339 sunflower
## 41
341 sunflower
## 43
320 sunflower
## 45
334 sunflower
## 46
322 sunflower
## 48
318 sunflower
## 49
325
meatmeal
## 51
303
meatmeal
## 52
315
meatmeal
## 53
380
meatmeal
## 58
344
meatmeal
## 60
368
casein
## 61
390
casein
## 62
379
casein
## 64
404
casein
## 65
318
casein
## 66
352
casein
## 67
359
casein
## 71
332
casein
b)
# Use the subset() function to construct a subset of the chickwts data frame where the
# chicks are fed with linseed.
chickwtslinseed
<-
subset(chickwts, feed ==
"linseed"
)
chickwtslinseed
##
weight
feed
## 11
309 linseed
## 12
229 linseed
## 13
181 linseed
## 14
141 linseed
## 15
260 linseed
## 16
203 linseed
## 17
148 linseed
## 18
169 linseed
## 19
213 linseed
## 20
257 linseed
## 21
244 linseed
## 22
271 linseed
c)
# Utilize the mean() function to determine the average weight of all chicks eating
# linseed from the chickwtslinseed subset.
mean(chickwtslinseed$weight)
## [1] 218.75
d)
# Create a new subset from the chickwts data frame where the chicks are not fed with
# linseed and use the mean() function to determine the average weight of all chicks not
# eating linseed from the chickwtsnolinseed subset.
chickwtsnolinseed
<-
subset(chickwts, feed !=
"linseed"
)
5
mean(chickwtsnolinseed$weight)
## [1] 269.9661
Problem 6
# Create a sequence using the seq() function called x from 0 to 6, which increments
# by 0.01.
x
<-
seq(
0
,
6
,
by=
0.01
)
# Produce a function called f() which takes the x variable as its parameter. If x is
# greater than 3, then y-values are determined by the function: (2*x) - (0.5*(xˆ2)).
# However, if that is not the case and x is less than or equal to 3, then y-values are
# determined by the function: (3*x) + 2.
f
=
function
(x)
{
if
(x >
3
)
{
(
2
*x) - (
0.5
*(xˆ
2
))
}
else
{
(
3
*x) +
2
}
}
# Create a function wrapper for function f() by utilizing the Vectorize() function.
f
=
Vectorize(f)
# Utilize the plot() function to produce a graph of the piecewise function, where the
# y-axis ranges from -10 to 15, the scattered plot values are outlined with an orange
# line and an appropriate title is included to describe the function.
plot(x, f(x),
ylim=
c(-
10
,
15
),
main=
"Piecewise Function on the Interval from 0 to 6"
,
col=
'
orange
'
)
6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
0
1
2
3
4
5
6
-10
-5
0
5
10
15
Piecewise Function on the Interval from 0 to 6
x
f(x)
Problem 7
a)
# Utilize the sample() function to create a data frame called dieRolls which generates
# 1000000 tosses from a 6-sided die with replacement.
dieRolls
<-
sample(
1
:
6
,
1000000
,
replace =
TRUE)
b)
# Utilize the factor() function to create a factor of the dieRolls frame set, where
# the level names are changed to non-numerical names of die sides.
dieRollsFactor
<-
factor(dieRolls)
levels(dieRollsFactor)
<-
c(
"One"
,
"Two"
,
"Three"
,
"Four"
,
"Five"
,
"Six"
)
c)
# Convert the dieRollsFactor data frame to a character factor vector using the
# as.character() function.
dieRollsChar
<-
as.character(dieRollsFactor)
d)
# Generate tables utilizing the table() function to compare and display results from
# all die roll data frames. When comparing the names, the levels from dieRolls are
# numerical, while the levels from dieRollsFactor and dieRollsChar data frames are
# non-numerical. While comparing outputs, results from dieRolls and dieRollsFactor
# data frames are both similar, while dieRollsChar data frame values differ from
# the other two.
7
table(dieRolls)
## dieRolls
##
1
2
3
4
5
6
## 166848 166627 166230 166901 166930 166464
table(dieRollsFactor)
## dieRollsFactor
##
One
Two
Three
Four
Five
Six
## 166848 166627 166230 166901 166930 166464
table(dieRollsChar)
## dieRollsChar
##
Five
Four
One
Six
Three
Two
## 166930 166901 166848 166464 166230 166627
e)
The dieRolls data frame takes the longest to produce a table, while the dieRollsFactor data frame requires
the shortest amount of time to generate a table.
# Use the built-in system.time() function to determine the total length of time to
# generate tables from all die roll data frames.
system.time(table(dieRolls))
##
user
system elapsed
##
0.04
0.00
0.05
system.time(table(dieRollsFactor))
##
user
system elapsed
##
0.02
0.00
0.02
system.time(table(dieRollsChar))
##
user
system elapsed
##
0.05
0.00
0.05
f)
The dieRolls.R file requires the least amount of memory with an approximate size of 4 MB, while the
dieRollsChar.R file takes the most amount of memory with an approximate size of 8 MB.
# Utilize the dump() function to produce an R file based on the data frame specified
# in the function parameter. In addition, use the file.info() function to return the
# sizes of the newly-created R files for comparison.
dump(
"dieRolls"
,
"dieRolls.R"
)
file.info(
"dieRolls.R"
)$size
## [1] 4125016
dump(
"dieRollsFactor"
,
"dieRollsFactor.R"
)
file.info(
"dieRollsFactor.R"
)$size
## [1] 4125111
dump(
"dieRollsChar"
,
"dieRollsChar.R"
)
file.info(
"dieRollsChar.R"
)$size
## [1] 7905541
8
Related Questions
Question 2
Jadual menunjukkan bilangan pelanggan (dalam juta)
dan jualan tahunan (dalam RM juta) untuk sampel 14
Outlet Pakaian Berjenama.
Table shows the number of customer (in millions) and
annual sales (in million RM) for a sample of 14 Branded
Apparel Outlet.
Store Customers (x) Annual Sales (y)
1
3.7
5.7
2
3.6
5.9
3
2.8
6.7
4
5.6
9.5
3.3
5.4
2.2
3.5
7
3.3
6.2
8
3.1
4.7
9
3.2
6.1
10
3.5
4.9
11
5.2
10.7
12
4.6
7.6
13
5.8
11.8
14
3.0
4.1
a. Draw a scatter diagram to show the relationship
between two variables.
Answer:
arrow_forward
Help. Please
arrow_forward
Question 21
The SSR:
A) Will increase if you increase the number of observations
B) Is a measure of the variation in Y that our model fails to explain
C) Is our preferred measure of goodness of fit
D) (a) and (b) are true, but (c) is false
E) (b) and (c) are true, but (a) is false
arrow_forward
Question 34 parts b, c , and d
arrow_forward
question 21 part c
arrow_forward
Exhibit 15-3
Pertain to the following data.
group1 group2 group3
4 11 1
9 11 6
10 10 4
Refer to Exhibit 15-3. What is the value of Fcrit ? Use a = 0.05.
arrow_forward
Evaluate the following and determine if the sequence
{an}
converges or diverges
20n2-5n +1
An
5n2
10n + 1
arrow_forward
• Part 1
Rework problem 13 in section 1 of Chapter 7 of your textbook, about the sleeping sickness epidemic, using the following data. Assume that each full team
consists of 1 doctor and 4 nurses, and that each half team consists of 1 doctor and 2 nurses. Assume also that there are 205 doctors and 655 nurses
available to serve on teams. Assume also that the each full team can inoculate 280 people per hour and that each half team can inoculate 150 people per
hour. How many full teams and half teams should be formed in order to maximize the number of inoculations per hour?
When you formulate a linear programming problem to solve this problem, how many variables, how many constraints (both implicit and explicit), and how
many objective functions should you have?
Number of variables: 2
Number of constraints: 4
Number of objective functions:
1
• Part 2
• Part 3
Formulate the linear programming problem for this situation. (Enter either the word Maximize or the word Minimize in the first…
arrow_forward
Question 34 parts e, f, and g.
arrow_forward
Question 18 of 18 (1 point) | Question Attempt: 2 of Unlimited
Send data to Excel
Arrange the leaves in order from smallest to largest.
Stems
Chock
A class of 20 students completed a math test. Their test results are gathered in the chart below. Construct a stem and leaf plot.
20 12 39 38
41 43 51 52
59 55 53 59
50 58 35 38
23 32 43 53
1
2
3
4
8
Leaves
00000
Nasta
✓ 10
57
11
OLDE
12
IA
14
Sua For Las
Ⓒ3003 McGraw HIR LLC. A Nights Sheenaid. Ters of Lir
arrow_forward
Section 2.3
Questions 7
Thank you for answering
arrow_forward
i mathxl.com/Student/PlayerHomework.aspx?homeworkld%3574125325&questionld=1&flushed%3Dfalse&cld=6161404¢erwin=
T'Mara Gilchrist &
P Do Homework - T'Mara Gilchrist- Google Chrome
Mat 122 - 80 Fall 2020
Homework: Section 6.2 Homework
HW S
2 of 10 (0 complete)
Score: 0 of 1 pt
6.2.11
Construct the truth table for the compound statement -(p v g).
Complete the truth table.
9 (p v q)
F
F
Enter your answer in the edit fields and then click Check Answer
All parts showing
Terms of Use Privacy Policy Copyright © 2020 Pearson Education Inc. All Rights Reserved.
Clear Al
search
a
arrow_forward
The chart type shown in Question #9 is useful for displaying ________________________ data. *
A) Univariate, Categorical
B) Univariate, Numeric
C) Bivariate, Categorical
D) Bivariate, Numeric
arrow_forward
Bookmarks Profiles
Tab
Window
Help
Do Homework - 1530 Module 4 Section 3.5 HW
earson.com/Student/PlayerHomework.aspx?homeworkId=674412092&questionid=6&flushed=false&cid=7842482¢erwin=yes
H 1530.303 Puckett
Lida Paul 06/19/24 1:29 AM
mework: 1530 Module 4
Question 3, 3.5.5
HW Score: 63.33%, 3.8 of 6
points
ction 3.5 HW
Part 1 of 5
Points: 0.8 of 1
Save
tion list
uestion 1
不
Use the side-by-side boxplots shown to complete parts (a) through (e).
X
y
question 2
0
30
30
60
60
90
90
120
n 1530 M
n 1530 M
Question 3
(a) What is the median of variable x?
The median of variable x is
(Round to the nearest integer as needed.)
Question 4
Incorrect:
Question 5
Question 6
Help me solve this View an example
Textbook
English (United States)
BAB
3
4
5
MacBook Pro
<6
E
R
T
Y
D
F
G
27
&
H
כ
* 00
8
Clear all
9
Check answer
Focus
O
J
K
L
P
+ 1/
لانه
{
arrow_forward
type not wright thx
arrow_forward
Evaluate the different types of visual representations which can be used to communicate the findings.
arrow_forward
Tab
Window
Help
Do Homework-1530 Module 4 Section 3.5 HW
GA
PlayerHomework.aspx?homeworkId=674412092&questionld=6&flushed=false&cid=7842482¢erwin=yes
Lida Paul
06/19/24 1:28 AM
⚫
Wed Jun 19 1:28 AM
X
The x +
dule 4
Question 6, 3.5.12
>
HW Score: 63.33%, 3.8 of 6
points
<
Save
Part 1 of 3
O Points: 0 of 1
53 Help
不
The following data represent the weight (in grams) of a random sample of 13 medicine 0.609 0.600 0.612 0.610
tablets. Find the five-number summary, and construct a boxplot for the data. Comment 0.610 0.599 0.605 0.605
on the shape of the distribution.
0.607 0.612 0.610 0.608
0.610
The five-number summary is
]. ], ], ]·
(Use ascending order.)
is
View an example
Textbook
ed States)
MacBook Pro
A)
Clear all
Check answer
(
&
$
%
4
5
6
7
8
9
R
T
Y
U
כ
F
G
H
O
Focus
J
K
L
V
B
N
M
P
n 1530 Module 4
-
In 1530 Module 4
Incorrect: 1
Λ
+ 11
[
الها
11
?
11
180
delete
re
arrow_forward
Which of the following is an example of a secondary data collection method?
Running experiments in a laboratory
B) Conducting observations in a natural setting
D
Accessing government records and databases
Conducting a survey of student where the data will be used
arrow_forward
Question 4: Create a boxplot of the variable WeightGain using ggplot
Plz use the info below thanks
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Related Questions
- Question 2 Jadual menunjukkan bilangan pelanggan (dalam juta) dan jualan tahunan (dalam RM juta) untuk sampel 14 Outlet Pakaian Berjenama. Table shows the number of customer (in millions) and annual sales (in million RM) for a sample of 14 Branded Apparel Outlet. Store Customers (x) Annual Sales (y) 1 3.7 5.7 2 3.6 5.9 3 2.8 6.7 4 5.6 9.5 3.3 5.4 2.2 3.5 7 3.3 6.2 8 3.1 4.7 9 3.2 6.1 10 3.5 4.9 11 5.2 10.7 12 4.6 7.6 13 5.8 11.8 14 3.0 4.1 a. Draw a scatter diagram to show the relationship between two variables. Answer:arrow_forwardHelp. Pleasearrow_forwardQuestion 21 The SSR: A) Will increase if you increase the number of observations B) Is a measure of the variation in Y that our model fails to explain C) Is our preferred measure of goodness of fit D) (a) and (b) are true, but (c) is false E) (b) and (c) are true, but (a) is falsearrow_forward
- Evaluate the following and determine if the sequence {an} converges or diverges 20n2-5n +1 An 5n2 10n + 1arrow_forward• Part 1 Rework problem 13 in section 1 of Chapter 7 of your textbook, about the sleeping sickness epidemic, using the following data. Assume that each full team consists of 1 doctor and 4 nurses, and that each half team consists of 1 doctor and 2 nurses. Assume also that there are 205 doctors and 655 nurses available to serve on teams. Assume also that the each full team can inoculate 280 people per hour and that each half team can inoculate 150 people per hour. How many full teams and half teams should be formed in order to maximize the number of inoculations per hour? When you formulate a linear programming problem to solve this problem, how many variables, how many constraints (both implicit and explicit), and how many objective functions should you have? Number of variables: 2 Number of constraints: 4 Number of objective functions: 1 • Part 2 • Part 3 Formulate the linear programming problem for this situation. (Enter either the word Maximize or the word Minimize in the first…arrow_forwardQuestion 34 parts e, f, and g.arrow_forward
- Question 18 of 18 (1 point) | Question Attempt: 2 of Unlimited Send data to Excel Arrange the leaves in order from smallest to largest. Stems Chock A class of 20 students completed a math test. Their test results are gathered in the chart below. Construct a stem and leaf plot. 20 12 39 38 41 43 51 52 59 55 53 59 50 58 35 38 23 32 43 53 1 2 3 4 8 Leaves 00000 Nasta ✓ 10 57 11 OLDE 12 IA 14 Sua For Las Ⓒ3003 McGraw HIR LLC. A Nights Sheenaid. Ters of Lirarrow_forwardSection 2.3 Questions 7 Thank you for answeringarrow_forwardi mathxl.com/Student/PlayerHomework.aspx?homeworkld%3574125325&questionld=1&flushed%3Dfalse&cld=6161404¢erwin= T'Mara Gilchrist & P Do Homework - T'Mara Gilchrist- Google Chrome Mat 122 - 80 Fall 2020 Homework: Section 6.2 Homework HW S 2 of 10 (0 complete) Score: 0 of 1 pt 6.2.11 Construct the truth table for the compound statement -(p v g). Complete the truth table. 9 (p v q) F F Enter your answer in the edit fields and then click Check Answer All parts showing Terms of Use Privacy Policy Copyright © 2020 Pearson Education Inc. All Rights Reserved. Clear Al search aarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Algebra & Trigonometry with Analytic GeometryAlgebraISBN:9781133382119Author:SwokowskiPublisher:Cengage
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage