Skip to Content
RStudioではじめるRプログラミング入門
book

RStudioではじめるRプログラミング入門

by Garrett Grolemund, 大橋 真也, 長尾 高弘
March 2015
Beginner to intermediate
276 pages
3h 31m
Japanese
O'Reilly Japan, Inc.
Content preview from RStudioではじめるRプログラミング入門

9章ループ

ループは、仕事を反復するためのRの方法です。Rはループ機能を持つため、シミュレーションのプログラミングに役立つツールになっています。この章では、Rのループツールの使い方を学びます。

score関数を使って現実の問題を解決しましょう。

このスロットマシンは、詐欺だと非難された実際のマシンをモデルにして作られています。このマシンは1ドルあたり40セントずつ払い戻しているように見えました。しかしメーカーは1ドルあたり92セント払い戻していると主張していました。scoreプログラムを使えば、実際の払戻率を計算できます。払戻率は、スロットマシンの賞金の期待値です。

9.1 期待値

無作為な事象の期待値は加重平均の一種です。期待値は、個々の可能な事象が持つ値にその事象が発生する確率を掛けたものの合計です。

期待値は、スロットマシンを無限回プレイしたときに得られる賞金の平均額だと考えることができます。この式を使って単純な期待値を計算してみましょう。次に、その式をスロットマシンに適用します。

第Ⅰ部で作ったサイコロのことを思い出してみてください。

die <- c(1, 2, 3, 4, 5, 6)

私たちがサイコロを振るたびに、サイコロは無作為に選択された値を返します。サイコロを振ったときの期待値は、次の数式で計算できます。

ここで、dieiは、サイコロを振ったときに得られる値で、1、2、3、4、5、6です。そしてP(diei)は、それぞれの値が出る確率です。サイコロが歪みがなければ、どの値も1/6という同じ確率で発生するはずです。そこで、私たちの式は、次のように単純化されます。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

PythonとJavaScriptではじめるデータビジュアライゼーション

PythonとJavaScriptではじめるデータビジュアライゼーション

Kyran Dale, 嶋田 健志, 木下 哲也
プログラミングRust

プログラミングRust

Jim Blandy, Jason Orendorff, 中田 秀基
ユーザーストーリーマッピング

ユーザーストーリーマッピング

Jeff Patton, 川口 恭伸, 長尾 高弘

Publisher Resources

ISBN: 9784873117157Other