# Can you do coding in R studio?

It's an R studio coding/assignment, pretty simple

## Get Help With a similar task to - Can you do coding in R studio?

##### Additional Instructions:

STA257: Probability, Statistics and Data Analysis I Assignment for credit Shahriar Shams Submission deadline: June 13, 11.59pm Toronto Time (Late submissions will not be accepted) Instructions on creating documents for submission • Please create 5 separate pdfs (one for each question). • I recommend using R-markdown(if you are familiar with it). If you are not familiar with R- markdown, you can write your answers using Microsoft Word and in the end save them as pdfs. Pdf is the only acceptable format of files. • You may submit hand written answers for some parts. In that case, take pictures of your hand written parts and embed then in your pdf. • We will use crowdmark for submission and grading. You will have to upload five separate pdfs as your answers to five separate questions. Crowdmark link to upload your documents will be emailed to you. Presentation of your answers for the entire assignment worth 1 point. Make sure your answers are organized, well written, easy to read/follow, graphs are appropriately sized and placed. Academic Integrity Each student will work alone. If you need clarification on any of these questions, you are allowed to ask questions on Piazza or ask questions during office hours. Don’t ask for solutions to anyone. Do not share your codes or answers on any platform. Question:1 You are playing a game where a fair die is rolled first and then a fair coin is tossed a number of times equal to the face of the die (e.g. if the die shows three, the coin is tossed three times, and this combination is considered as one game). a)[1 point] Let D be the number on the face of the die and X be the number of heads(H) you can get in any game. • Write down the joint probability mass function of DandX and calculate the marginal probabilities. b)[1 point] By calculating appropriate quantities separately, check these identities • E[D] = E(E[D|X]) • E[X] = E(E[X|D]) c)[1 point] By calculating appropriate quantities separately, check this identity • V [X] = E(V [X|D]) + V (E[X|D]) Expected output: (a) Numeric calculations and a joint pmf table. (b) and (c) Numeric calculations with justifications. © 2020 Shahriar Shams, University of Toronto Page 2© 2020 Shahriar Shams, University of Toronto Page 2© 2020 Shahriar Shams, University of Toronto Page 2 Question:2 Suppose you are working for TD’s car insurance program. You are helping the leadership team to set the premium rate for the upcoming year. You are told that there are currently 1 million customers who have their car insurance through TD. Each customer has a 0.05% of getting into a major accident and a 1% chance of getting into a minor accident. To keep our calculations simple, let’s assume a client will only be involved in a maximum of one accident in a year. Let Y be the amount in dollars that a customer is required to pay to repair his/her vehicle anytime it is involved in an accident. And let X be the accident type(0=no accident,1=minor accident,2=major accident). Let Y ’s probability density function be f(y) = 13000e − 13000 y; y ≥ 0; when X = 1 and f(y) = 120000e − 120000 y; y ≥ 0; when X = 2 a)[2 points] Calculate E[Y ] and V [Y ]. b)[1 point] There is a thousand dollar deductible in every insurance plan, which means TD will not pay anything to the customer if the repair cost is less or equal to $1000. And for any repair cost that is above $1000, the customer pays the first $1000 and TD will pay the rest. Let Z be the dollar value that TD needs to pay to each customer during the year. Calculate E[Z]. Expected output: (a) and (b): Numeric calculations and justifications. © 2020 Shahriar Shams, University of Toronto Page 3© 2020 Shahriar Shams, University of Toronto Page 3© 2020 Shahriar Shams, University of Toronto Page 3 Question:3 (Note: This question relates to Central Limit Theorem which we will cover in Lecture 11. This question will make much more sense once we have discussed this in the lecture. For now, just try to follow the steps in each part) a)[1 point] Write an R function that • draws two random numbers(n = 2) from a standard normal distribution, • calculates the average of these n numbers and returns it. Now replicate this function 100000 times and save the output. Finally, plot a density curve using these saved outputs. What distribution do you think it looks like? Give the name of the distribution and the numeric values of the parameters. b)[1 point] Write another function that does exactly the same task that you have done in part(a), but this time draw samples from a Uniform distribution on [0, 1] (instead of standard normal). Replicate this function 100000 times and plot a density curve using the outputs from the function. • You should get a different plot this time in comparison to the density that you have found in part (a). • Try increasing the value of n (to 3,4,5,. . . ) and comment at which value of n you start to see the density that you have seen in part(a). c)[1 point] Replicate part(b), but this time drawing samples from Exponential(λ = 1/1000) and comment at which value of n you start to see the density that you have seen in part(a). Expected output: a) R codes and one density plot b) R codes and the density plot corresponding to the n value that you picked as your answer. c) R codes and the density plot corresponding to the n value that you picked as your answer. © 2020 Shahriar Shams, University of Toronto Page 4© 2020 Shahriar Shams, University of Toronto Page 4© 2020 Shahriar Shams, University of Toronto Page 4 Question:4 Note-1: “Convergence in distribution” is a technical term which naively means one variable taking the shape of another variable. (You saw an example in Lecture 3: binomial starts to look like Poisson for large n). Note-2: The parameter of a Chi-sq distribution is often called “degrees of freedom”(df). Question: By generating a large set of random numbers from appropriate distributions demonstrate these following properties graphically, a)[1 point] Poisson(λ) converges in distribution to Normal when λ→∞. b)[1 point] Chi− sq(df) converges in distribution to Normal when df →∞. c)[1 point] X ∼ Poisson(λ1), Y ∼ Poisson(λ2) and X and Y are independent. Then X + Y ∼ Poisson(λ1 + λ2). Code hint: for generating random numbers look at R codes: rpois(), rchisq() and rnorm(). Expected output: In all three parts, provide the R codes, some plots, your choice of parameter values and a brief summary of what you have found. © 2020 Shahriar Shams, University of Toronto Page 5© 2020 Shahriar Shams, University of Toronto Page 5© 2020 Shahriar Shams, University of Toronto Page 5 Question:5 a)[1 point] Suppose X ∼ Poisson(λ1), Y ∼ Poisson(λ2). And X and Y are independent. The task here is to calculate the conditional pmf of X, given X + Y . Start by deriving the expression of P [X = k|X + Y = n] What distribution do you think it is? Give the appropriate parameters. Make sure to show detailed work. b)[1 point] Provide a real life example of this conditional probability that you calculated in part (a). Do not search online, try to come up with your own example. **************************** End of Questions *************************** © 2020 Shahriar Shams, University of Toronto Page 6© 2020 Shahriar Shams, University of Toronto Page 6© 2020 Shahriar Shams, University of Toronto Page 6 Question:1 Question:2 Question:3 Question:4 Question:5

## Related Questions

Tutlance Experts offer help in a wide range of topics. Here are some of our top services:

- Math homework help
- Nursing homework help
- Statistics homework help
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Programming homework help
- Coursework writing help
- Term paper writing help
- Biology homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing services
- Chemistry homework help

Post your project now for free and watch professional experts outbid each other in just a few minutes.