Home Page > > Details

Test whether the function works for x = numeric(0) and for any other numeric

vector x.

3. The Body Mass Index (BMI) is used to determine a person’s corpulence. It is calculated

using the formula:

BMI = Weight (kg)

Height2

(m)

(a) [4 marks] Write an R function that calculates your BMI and round it to 3 decimal

places.

(b) [6 marks] Consider the following BMI and weight categories:

Underweight if BMI < 18.5

Normal weight if BMI ∈ [18.5, 25)

Overweight if BMI ∈ [25, 33)

Obesity if BMI ≥ 33

Write an R function which takes the result of (3a) as a single argument BMI, a

and returns the corresponding category. For example:

> weight.category(21.133)

This corresponds to category: normal weight

4. Consider an asymmetric random walk when the probability of going one step up is 0.55

and the probability of going one step down is 0.45. Let Xn denotes the n-th step in this

random walk. Then, X1, X2, · · · are independent and identically random variables with

Xn =

(

+1 w.p. 0.55

−1 w.p. 0.45

Assume that {Dn}n≥0 is a sequence showing the distance from the origin (starting

point). So,

D0 = 0

Dn = Dn−1 + Xn for n = 1, 2, · · ·

(a) [6 marks] Write an R function which takes the number of steps as its single argument

and returns a vector of distances (for instance shows a sequence of realization

of distances D0, D1, · · · , D10 for the argument n = 10).

Hint: sample() function is helpful.

(b) [6 marks] By using the function in (4a) write a new R function (with single

argument) which generates one realization of the walk (starting from the origin)

and counts the total number of steps taken in the right hand side of the origin

(for instance, one example could be the case of starting from the origin with the

sequence of steps

X1 = +1, X2 = −1, X3 = −1, X4 = +1, X5 = −1, X6 = +1.

Then, the sequence of distances is

D0 = 0, D1 = 1, D2 = 0, D3 = −1, D4 = 0, D5 = −1, D6 = 0.

Here, your function should returns 2 as the number of steps taken in the right hand

side of the origin).

Contact Us(Ghostwriter Service)

- QQ：99515681
- WeChat：codinghelp2
- Email：99515681@qq.com
- Work Time：8:00-23:00

- Cis 484 Assignmenthelp With ,Ghostwrit... 2020-09-27
- Ghostwriter Kit206 Course Assignment,H... 2020-09-27
- Comp2100 Assignmenthelp With ,Ghostwri... 2020-09-27
- Msbd5015 Assignmentghostwriter ,Python... 2020-09-27
- Programming Assignmentghostwriter ,Jav... 2020-09-27
- Cisc 360 Assignmenthelp With ,Ghostwri... 2020-09-27
- Cs 570 Assignmenthelp With ,Java Progr... 2020-09-27
- Help With Isys 1108 Assignment,Help Wi... 2020-09-27
- Data Assignmentghostwriter ,Java，C++ ... 2020-09-26
- Csc220 Assignmenthelp With ,Data Assig... 2020-09-26
- Ghostwriter Csc220 Assignment,Help Wit... 2020-09-26
- Bridging Coursework 2020-09-26
- Comp Sci 3004/7064 Operating Systems ... 2020-09-26
- Comp9311 20T2 - Assignment 2 2020-09-26
- Ipal Capstone Project 2020-09-26
- Ipal Programming In R - Week 2 Assign... 2020-09-26
- Csc 503/Seng 474 Data Mining Assignmen... 2020-09-26
- Assignment 1 Cmpt 307 2020-09-26
- Csci 2300 Lecture Exercise 5 2020-09-26
- Csci 2300 Lab 4 2020-09-26

Contact Us - Email：99515681@qq.com WeChat：codinghelp2

© 2014 www.asgnhelp.com

Programming Assignment Help！