STAT 415 and STAT 515

STAT 415 and STAT 515 Project 1 Fall 2019 Page 1
Instructions:
• Follow the instructions indicated in this project carefully.
• This project should be considered to be an exam. That means that you should do your own work.
• You should not speak about this exam to other students in the class.
• You may use class resources and other R related resources found in the library or internet.
• Any indications of cheating on this project will result in a failure in the course.
• The project should be turned in using blackboard. Note that you will turn in exactly three files:
simfunction.txt This is a text file that contains the R function that you should create for Part 1. Name the
file exactly as specified.
project.pdf This is a PDF file that contains the code and results from the indicated simulation runs, along
with an narrative that answers the question posed in Part 2. Be sure that you gather enough data from
your simulations to justify your conclusions. Any graphics that you use should be imbedded in the PDF
file using the LATEX package graphicx. Name the file exactly as specified.
help.pdf This is a PDF file generated using LATEX that contains a help file for your function written by in in
the same style as the help files used in R. Name the file exactly as specified.
• Relax, take your time, and have fun!
STAT 415 and STAT 515 Project 1 Fall 2019 Page 2
As the last rays of sunshine cast an amber pall over your office window one fall evening, and you watch the final
rays blink from the sky, your phone rings and interrupts your quiet solitude and snaps you back to reality. It is a

STAT 415作业代写、R编程语言作业调试、代写R课程设计作业
consulting client, and you know this will be a tough phone call. This client has many questions, and few answers. To
compound matters, they are always questions about probability, a subject which they seem to have no training in,
and little intuition. That is why you are their consultant, to answer questions in a way that they can understand and
appreciate. That is why you get those excellent consulting fees. You sigh and take the phone call, and immediately
you feel a new headache rooting itself deep in you head. It is going to be a long night.
The client is the famed Antoine Gombaud, a rich gambler from France. Mr. Gombaud is fascinated with gambling
games, and likes to entertain at parties with fashionable games involving dice and cards. He is suave and personable,
but not good at mathematics, and so he has hired you to do his math for him. In particular he needs to know how
to set payouts for the games that dreams up. The payouts need to be fair. Obviously, if he pays his friends to much
for winning a game then he will soon lose all of his money. On the other hand, if he pays too little, then they will
not want to play the games as they will lose all of their money. The usual way to set a payout for a game is based on
expected winnings, or the long-term average amount won or lost by the gambler in repeated plays of a game. There
are theoretical methods for computing these values, but Mr. Gombaud does not trust these methods. However, he
does trust simulating the game on a computer, and looking at the average winnings over large number of simulated
games. Thankfully, he also knows how to run R.
For example, consider the very simple game of flipping a fair coin once. Suppose that a gambler will win against
Antoine if the coin flip is Heads. Suppose the gambler pays $1 to play the game Antoine is considering paying back
$3 if the flip is Heads ($2 as a prize, plus the $1 that was bet for a net loss of $2). Otherwise, he will keep the $1.
Standard probability theory easily solves this problem by stating the Antoine is expected to lose $0.50 per play of
the game. But Antoine does not like theory, so the same question can be explored through simulation. We could
simulate a large number, say b, coin flips using R. For each Heads observed in the simulation we would subtract $2
from the total winnings and if the flip is Tails then we would add $1 to the winnings (This is taken from Antoine’s
viewpoint). We would then add up these simulated winnings and divide by b to get an estimate of the expected gain
(or loss) for each play of the game.
The game that Antoine is interested in is only a little more complex. Antoine suggests rolling a six-sided fair die
n times. If a six is not rolled in the n rolls of the die then the player receives w + 1 dollars, equal to the one dollar
they payed to play the game and w dollars of winnings. In this case Antoine would have net winnings of −w dollars.
If a six is rolled at least once in the n rolls then Antoine keeps the one dollar the player paid to play the game. In
this case Antoine would have net winnings of one dollar.
1. Write a function in R that follows the specifications:
• The name of the function should be sim.game.
• The arguments of the function should be n, w, b, plot, seed, and ..., where b has a default value of
1000, plot has a default value of FALSE, and seed is an optional argument.
• The function should simulate b plays of the game and keep track of how much Antoine would win or lose
for each simulated play of the game.
• If seed is specified, then the function set.seed should be executed with the value specified by seed.
Otherwise, the set.seed function should not be executed at all.
• The function should return a data frame with the following columns:
– Columns 1 through n should contain the results of the n rolls of the fair die (integer named "Roll
1" to "Roll n").
– Column n + 1 should identify the winner as the player ("P") or as Antoine ("A") (factor named
"Winner").
– Column n + 2 should show how much Antoine won or lost on the game (double named "Winnings").
– Column n + 3 should show the average winnings for Antoine over the games completed to that time
(double named "Average").
• If plot=TRUE then the function should produce a plot. The horizontal axis of the plot should indicate the
simulated game and the vertical axis should indicate the average winnings at that time. The plot should
be nice looking with proper labels. The argument ... should be passed to the plot command for optional
plot specifications.
STAT 415 and STAT 515 Project 1 Fall 2019 Page 3
As an example, a run of the function should look like:
sim.game(n=5,w=2,b=10,plot=TRUE,col="blue")
Roll 1 Roll 2 Roll 3 Roll 4 Roll 5 Winner Winnings Average
1 1 1 2 3 3 P -2 -2.0000000
2 6 2 4 4 1 A 1 -0.5000000
3 3 1 6 2 1 A 1 0.0000000
4 2 6 3 2 2 A 1 0.2500000
5 2 2 1 4 1 P -2 -0.2000000
6 4 1 5 2 5 P -2 -0.5000000
7 2 5 2 2 6 A 1 -0.2857143
8 5 3 4 3 3 P -2 -0.5000000
9 1 2 4 2 3 P -2 -0.6666667
10 4 2 3 1 2 P -2 -0.8000000
In this case the following plot would be produced
2 4 6 8 10
-2.0 -1.5 -1.0 -0.5 0.0
Game
Average
Average Winnings from 10 Simulated Games
Full credit will be given to functions that do at least come error checking. Turn in this function to Blackboard
in a text file called simfunction.txt.
2. Run your function with n=10, b=100 for a range of values of w. Using these results, suggest a value of w that
Antoine should use that would allow him to make some money, but not so much that players would not like to
gamble with him. Note that w need not be an integer. Include the code and results from your runs, as well as
your suggestions for w in a PDF file generated by LATEX named project.pdf.
3. Write a help file for your code in the same style as the help files used in R. Include a description of all of the
arguments, the default values, how the function works, and what type of object it returns. Include one or two
examples. This should be contained in a PDF file generated by LATEX named help.pdf.

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codehelp

原文地址:https://www.cnblogs.com/python34/p/11622611.html

时间: 2024-12-12 03:10:12

STAT 415 and STAT 515的相关文章

LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例

二次联通门 : LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例 /* LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例 很显然 贪心方程哦不 dp方程为 f[i][j]=f[i-1][j-k*k] 但是这样的话复杂度就是O(N ^ 5) 那么就用bitset优化一下 就ok了 */ #include <iostream> #include <cstdio> #include <bitset> void

LibreOJ 515 贪心只能过样例

题目链接:https://loj.ac/problem/515 题意: 给n(测试数据全是100)个数,第i个数x的取值可以在[a,b](1<=a,b<=100),求sigma(x*x)的取值有多少种. 题解: 这道题很容易得出一个O(n^5)的复杂度的一个dp(暴力),但是很明显这个复杂度是不行的. 这道题可以产生的最大的数是100*100*100=1e6,于是我们可以借助一个叫做bitset的东西来优化一下我们的dp(暴力). bitset可以看做一个bool数组(每一位都是0/1),也可

在SpringMVC中使用@RequestBody和@ResponseBody注解处理json时,报出HTTP Status 415的解决方案

我在使用SpringMVC的@RequestBody和@ResponseBody注解处理JSON数据的时候,总是出现415的错误,说是不支持所提交数据格式,我在页面中使用了JQuery的AJAX来发出JSON数据给服务器: $.ajax({ type:'post', url:'${pageContext.request.contextPath }/requestJSON.action', contentType :'application/json;charset=utf-8', //数据是JS

36. leetcode 415. Add Strings

415. Add Strings Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain

ajax往后台传json格式数据报415错误

问题描述: ajax往后台传json格式数据报415错误,如下图所示 页面代码 function saveUser(){ var uuId = document.getElementById("uuid").value; var idCard = document.getElementById("idCard").value; alert(uuId+idCard); // var result = new Object(); // result.uuId = uuI

python发送post请求发送json数据时,报415的原因和处理方法。

415   Unsupported media type. 不支持MEDIA类型 这代表服务无法处理你提交的数据格式. 处理起来很简单,在你的header里指定一下格式. 加上一句代码 headers = {"Content-Type": "application/json"}

每日站立会议--5-15

项目名称:Floaty Fish 成员:张永.吴盈盈.王丹.周其范.董芳健 会议时间:20:30-21:00 会议地点:学院楼 成员 done doing 遇到的问题 张永       无 董芳健 无  编写用户手册,发布博客  无 王丹 对游戏过程中提示速度加快的提示,告诫玩家接下来游戏的难度会提升      加入了音乐特效      无 周其范     完成了测试报告    项目开发总结报告    无 吴盈盈        无每日站立会议--5-15,布布扣,bubuko.com

人生的诗&middot;411~415节

411.  剔骨 拿一把剔骨的刀 将自己的余年点点剔除 所有的怨憎会,爱别离,求不得如同肉台上那些淋漓的暗色的腐肉 决然地剔除 于是,生命便只剩下"无",只剩下"空" 但这一份清风明月,小舟沧海的"无"与"空"又是让人极期许的 可仰望星空 看见那灿烂的烟火 又会不自禁地渴望 于是年华开始背乱荒诞 如同一幕悲惨的哑剧 412.  荒凉 你所看不到的 那是好大的一片荒凉 纵然你用奢靡的放纵的繁华去填补它 也终是填不满的 而这片荒凉

JSP ajax跨域问题 怎么处理 原因:CORS 头缺少 &#39;Access-Control-Allow-Origin&#39;)。 ajax http 415

/** * Project Name:cm2mManage * File Name:CrossSiteFilter.java * Package Name:com.yoxnet.serverframework.base * Date:2016年4月27日下午4:52:51 * Copyright (c) 2016, [email protected] All Rights Reserved. * */ package com.zhl.sms.filter; import java.io.IOEx