Question: Write an R script that does the following: 1) Loads the given data into a list. 2) Converts the data from a list into a
Write an R script that does the following:
1) Loads the given data into a list.
2) Converts the data from a list into a vector. (use the unlist function)
3) Counts the number of heads in the first 10 elements of the list, the first 50, and the entire 150. Keep these three values in three separate variables.
4) Defines a function for the likelihood P(data|p). This should accept a list containing the sample, and the parameter p. Or, you can define a three-parameter function that takes the number of successes, the total number of coin flips, and p. Either way is fine. In the latter case, you will call the function with the results from part 3.
5) Plots the output of the function you defined in 4) with a. the first 10 elements of the data, b. the first 50 and c. the first 150, with p ranging from 0 to 1. (x-axis is p, y axis is the output). So you should have three plots.
data.txt
0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1 1 0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 0 0 1 1 1 0 1 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
