CS544 Module 2 Assignment
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CS544 Module 2 Assignment
Part1) Probability - 25 points
Use the Bayes theorem to calculate the following probabilities. Show the individual steps of the Bayes theorem. You can use R for the calculations. Use the Word document for this part.
Suppose that in a particular state, among 10000 people surveyed, 4250 people are in the age
Out of those in the age group 18-34 years, 1062 people had a BMI of above 30. Of those in the
30.
a) What is the probability that a randomly selected person in this survey will have a BMI of
b) If a randomly selected person had a BMI of above 30, what is the probability of that person
c) If a randomly selected person had a BMI of above 30, what is the probability of that person
d) If a randomly selected person had a BMI of above 30, what is the probability of that person
e) If a randomly selected person had a BMI of above 30, what is the probability of that person
Part2) Random Variables - 25 points
Consider a game which involves rolling three dice. Write the R code for the following.
Using the rollDie function from the prob library, setup the sample space for this experiment with
a) The sum of the rolls is greater than 6 but less than 10.
b) All the three rolls are identical. Sample Output for outcomes:
Sample Output for probability:
c) Only two of the three rolls are identical.
d) None of the three rolls are identical.
e) Only two of the three rolls are identical given that the sum of the rolls is greater than 6 but
Part3) Functions - 20 points
Using a for loop or a while loop, write your own R function,
For example, if n = 5, the first five even numbers are 2, 4, 6, 8, 10 and the required result is
22 + 42 + 62 + 82 + 102 = 220.
Test your function as follows:
Now, without using any loop, write your own R function,
Part4) R - 30 points
Initialize the Tesla stock data for the year 2021 using the read.csv function as shown below:
tsla <- read.csv("https://people.bu.edu/kalathur/datasets/TSLA.csv") The first 6 rows of the dataset are as shown below:
Provide the simplest R code and corresponding outputs for the following.
The code should work for any given dataset.
a) Store the result of the summary function for the Close attribute as the variable sm. Change
b) Produce the output for the minimum price of the Tesla closing value in the dataset as shown
c) Produce the output for the maximum price of the Tesla closing value in the dataset as shown
d) Based on the dataset, what is the probability that on any given day, the Tesla closing price would be greater than the opening price?
e) Based on the dataset, what is the probability that on any given day, the Tesla trading volume
f) Based on the dataset, what is the probability that on any given day, the Tesla closing price
g) Suppose you bought 1 share of Tesla stock on each day in the dataset at its open price. How
h) Suppose you bought 1 share of Tesla stock on each day in the dataset at its low price. How
i) Suppose you bought 1 share of Tesla stock on each day in the dataset at its high price. How
Submission:
When the term lastName is referenced, please replace it with your last name.
Create a folder, CS544_HW2_LastName and place the following files in this folder.
Provide all R code in a single file, CS544_HW2_LastName.R. Clearly mark each subpart of each question.
Provide the corresponding outputs from the R console in a single Word document,
_
Archive the folder (CS544_HW2_LastName.zip). Upload the zip file to the Assignments section of Blackboard.
2022-05-06