R代写_R语言作业代写 MAS468/6002/6024 Assignment 3

MAS468/6002/6024 Assignment 3

r代写范例:R语言作业代写 The Assignments should be your own work and should be undertaken in accordance with the University’s rules for non-invigilated

You should use R Markdown for this assignment. The submission deadline is noon on Friday 20th December 2019. Use R Markdown to produce a pdf file and submit the pdf file on the TurnitinUK Assignments tab on the MAS6002/6024/468 MOLE page.

A Description of the Game  R语言作业代写

The basic idea of the game is for the player to move around the board (shown in Figure 1) collecting letters to form the word ‘cat’. The rules are as follows:


  1. the players first move is to pick a randomly chosen square to start on (each square has the same probability of being chosen as the starting square);


  2. on each susequent turn, the player moves a number of steps, X, where X is a random variable with a Poisson distribution with known parameter λ (if X = 0 then the player doesn’t move);


  3. when a player moves they can only move right, left, up or down and are equally likely to move in each of these four directions;


  4. if the player is to move more spaces than are available on the board in the specified direction, then they stop at the final square available in that direction - for example if they start on B7 and are to move four spaces to the right then they stop on B8 - if they start on F2 and are to move three squares down then they stop on H2;


  5. they can collect the letter from any square they land on (including the starting square) provided they don’t already have that letter in their collection (i.e. they can have at most one of each letter in their collection);


  6. the game ends when they have collected the letters “c”, “a” and “t” in any order;


  7. ignore the fact that two squares are green in this part of the question;


R语言作业代写

Questions
Part 1  R语言作业代写

Below is some R code that places the letters in Table 1 in an 8 by 8 matrix. I recommend you use this method to store the letters in the letter grid, but you don’t have to if you decide there is a better approach. lgrid <- matrix(NA, nrow = 8, ncol = 8)

lgrid[1,] <- c("r", "l", "q", "s", "t", "z", "c", "a")
lgrid[2,] <- c("i", "v", "d", "z", "h", "l", "t", "p")
lgrid[3,] <- c("u", "r", "o", "y", "w", "c", "a", "c")
lgrid[4,] <- c("x", "r", "f", "n", "d", "p", "g", "v")
lgrid[5,] <- c("h", "j", "f", "f", "k", "h", "g", "m")
lgrid[6,] <- c("k", "y", "e", "x", "x", "g", "k", "i")
lgrid[7,] <- c("l", "q", "e", "q", "f", "u", "e", "b")
lgrid[8,] <- c("l", "s", "d", "h"," i", "k", "y", "n")

Write an R function that has arguments corresponding to:

• the current location (position in the matrix);
• λ; and that simulates the value of X ∼ P o(λ), and returns the position after the player has moved. You can create additional functions that are called by this function if it is helpful.

Part 2

Write an R function to implement playing the game as described above and to count the number of moves required to finish the game (the initial placement on the board counts as move 1). Your function should call the function created in Part 1 and may call other functions you write, if you decide this is needed. Note that based on the rules of the game, it seems there is no need to collect letters other than “c”, “a” or “t”.

However, in later questions the other letters are needed, so I suggest you allow the player to collect any letter to avoid the need to change your code later.

Part 3  R语言作业代写

Compare the estimated probability distributions of the number of moves required to complete the game for λ = 1 and λ = 4.

Part 4

The game is now modified. The rules are the same as previously described with the followng additional rules: if the player lands on a green square:


  1. they first pick up the letter if they don’t already have the letter in their collection;

  2. they do not check to see if their collection contains the work “cat” at this point;

  3. each letter in their collection is then replaced in the following way:
    • each of the letters “a” to “y” is replaced by the letter one further along the alphabet sequence, so the collection of letters “a”, “f” and “u” would be replaced with the letters “b”, “g” and “v”;
    • “z” is replaced by “a”;


  4. they now check to see if their collection of letters contains the work “cat”;


  5. if they don’t move, the above process is repeated until they move off of the green square. Modify your function in Part 2 to allow for this change in the rules of the game.

Part 5  R语言作业代写

Simulate the estimated probability distribution of the number of moves required to complete the game for λ = 1 using these new rules. Compare it with the distribution obtained with λ = 1 in Part 3. Briefly discuss why these new rules might cause these differences in the two distributions. What else to include/consider in your answers

As well as answering the questions directly, where appropriate, you need to justify your choice of the simulation parameters under your control. In this assignment as well as being marked on your answers to the questions, you will be marked on your ability to code efficiently in R, using a wide range of programming tools where
appropriate. Your code should be easily to follow but elegantly coded.

Administrative Information

Marking is anonymous, so do not write your name anywhere in the report. Your registration number should be shown on the first page of the report. You should submit a single pdf file for this assignment. The report should be named studentnumber-modulenumber-A3.pdf.

Report Structure and Content

There is no page limit for the report but as a guide 5 pages or fewer should be sufficient. Think about how to communicate your answers concisely and clearly whilst providing sufficient detail. Unnecessarily long reports will be penalized. Just answer the questions directly and justify your answers. Use R Markdown to produce
your pdf file. Make sure all the code used is visible in the report (use echo = TRUE). There is an optional R Markdown assignment template on MOLE that you can use use if you prefer. Describe what the R code does where you think another MSc student might not easily understand it (for example if you are using functions
not in the R notes for this module).

Assessment and Feedback  R语言作业代写

The Assignments should be your own work and should be undertaken in accordance with the University’s rules for non-invigilated assessment. Marks will be given on the scale described in Chapter 1 of the notes. You will receive individual feedback and some general comments will be posted on MOLE.

 

发表回复

客服一号:点击这里给我发消息
客服二号:点击这里给我发消息
微信客服1:essay-kathrine
微信客服2:essay-gloria