Basic Programming Concepts

2 Flipping a Fair Coin (aka: Basic Random Numbers) [Applied]
• Use R to simulate a single fair coin toss. Your code should simply print “Heads” or “Tails” to the screen once every time you run it, each time with a probability p = 1/2 for a head or a tail.
• Using a for loop, simulate 100 tosses of a fair coin and count how many heads you get in a variable called total which you print out after the loop.
• Optional/advanced Now repeat without resorting to a for loop. Can you do it in just two lines of code?

3 Simulating Random Numbers [Applied]
A test is graded from 0 to 50, with an average score of 35 and a standard deviation of 10.
• Simulate data for a class of 25 students who took the test in R. Assume scores are drawn from a normal distribution. Use the rnorm() function to create random numbers drawn from a normal distribution – but make sure to adjust the mean and standard deviation accordingly.
Use ?rnorm to find out how.
• Do you note any issues with the approach using rnorm to generate the numbers?
• Bonus: Tests are not usually graded as full precision floting point numbers. Can you figure out how to simulate test scores that are rounded to the nearest .5?

DETAILED ASSIGNMENT

20201007045159problem_set_1

Powered by WordPress