外国書購読 Day1
Day1:Guidance and Introduction

Soichi Matsuura

Guidannce and Introduction

Introduction

  • This lecture is designed to introduce the concept of audit analytics and how it can be used in auditing financial statements.
  • The course will cover the basics of financial accounting and auditing, and how data science can be used to improve the audit process.
  • The course will also cover the use of R programming language for data analysis and visualization.
  • This course never requires any prior knowledge of R programming language, but some basic knowledge of accounting or auditing is recommended.

Course Objectives

  • Understand the basics of financial accounting and auditing
  • Learn how data science can be used in auditing financial statements
  • Learn how to use R programming language for data analysis and visualization

Textbook

Audit Analytics
  • Title: Audit Analytics: Data Science for the Accounting Profession (Use R!)
  • Author: Westland, J. C.
  • Publisher: Springer
  • Year: 2019

配布するので,買わなくてもよいです。

Grade

The final grade will be based on the following components:

  • Attendance and Participation: 40%
  • Presentation: 40%
  • Final Report: 20%

Schedule

  • Day 1: Fundamentals of Auditing Financial Reports (Chapter1)
  • Day 2: Foundations of Audit Analytics (Chapter 2)
  • Day 3: Analysis of Accounting Transactions (Chapter 3)
  • Day 4: Risk Assessment and Planning (Chapter 4)
  • Day 5: Analytical Review: Technical Analysis (Chapter 5)
  • Day 6: Intelligence Scanning (Chapter 6) ?
  • Day 7: Design of Audit Programs (Chapter 7)
  • Day 8: Interim Compliance Tests (Chapter 8)

Assignments

  • This class requires about 4 pages translation of the textbook for all students.
  • The translation should be submitted by next week.
  • The translation will be evaluated based on the accuracy of the translation and the quality of the writing.

前半戦 第3限

Auditing

  • An audit is an independent examination of the records of an organization to ascertain how far the financial statements as well as non financial disclosures, present a true and fair view of the concern.
  • It also provides assurance that the systems of record-keeping are well-controlled and accurate as required by law. Auditing has become such a ubiquitous phenomenon in the corporate and the public sector that academics started identifying an Audit Society (Power 1997). 堀口先生訳「監査社会」

History of Auditing

  • The earliest surviving mention of a public official charged with auditing government expenditure is a reference to the Auditor of the Exchequer(財務省) in England in 1314 (Matthews 2006).
  • The medieval Latin term was auditus compoti from Latin auditus “a hearing,” at a time that literacy levels were low, and an official examination of accounts was presented orally.
  • Auditing initially existed primarily for governmental accounting and was concerned mostly with record-keeping rather than accounting procedures (Matthews 2006). It was not until the Industrial Revolution in the eighteenth century that auditing began evolving into a field of fraud detection and financial accountability.

  • The early twentieth century saw the standardization of ‘auditors’ testing methods and reporting practices and a growing role by banks and shareholders for public companies. Auditors developed a system for examining a representative sample of a company’s transactions, rather than examining each transaction in detail, allowing audits to be completed in less time and at lower costs.

  • By that time, audit findings were regularly presented as standard “Independent Auditor’s Reports” accompanying a firm’s financial statements.
  • Statistical sampling of transactions is now the industry standard in performing audits.
  • As a consequence, computer tools to conduct statistical samples and opinions based on them are an integral part of modern auditing.
  • It is only when gross errors or fraudulent activities are uncovered that comprehensive audits are performed.
  • As businesses have increased in complexity, such “risk-based” auditing has evolved to make auditing more efficient and economical.

推薦図書1

If you want to learn a computer based auditing tools for Python, This book is recommended.

  • 稲垣・小澤・野呂・蜂谷 (著)
  • Pythonではじめる 会計データサイエンス
  • 2023年出版
  • 中央経済社

Pythonではじめる 会計データサイエンス

推薦図書2

If you want to learn a statistical accounting and finance research, This book is recommended.

  • 笠原・村宮 著
  • 実証会計・ファイナンス : Rによる財務・株式データの分析
  • 2022年出版
  • 新世社

実証会計・ファイナンス
  • Risk-based auditing starts by assessing whether an audit is even needed, based on a review of information in the financial statements.
  • Through audits, stakeholders may effectively evaluate and improve the effectiveness of risk management, control, and corporate governance.
  • In the USA, audits of publicly traded companies are governed by rules laid down by the Public Company Accounting Oversight Board (PCAOB), which was established by Section 404 of the Sarbanes–Oxley Act of 2002.
  • Such an audit is called an integrated audit, where auditors, in addition to an opinion on the financial statements, must also express an opinion on the effectiveness of a company’s internal control over financial reporting, in accordance with PCAOB Auditing Standard No.5.

Computers in Auditing and the Birth of Audit Analytics

  • Increased data availability, more powerful computing, and an emphasis on analytics-driven decision in business has created a plethora of jobs in data science.
  • There are around 2.5 million openings (and increasing) for data analytics jobs in the USA at any time.
  • A significant share of employees analyze data with Microsoft Excel or other spreadsheet programs like Google Sheets.
  • While Excel and SAS are widely used tools, they have serious limitations.
  • Nor do they have a large community of contributors constantly adding new tools.

R or Python

  • For those who have reached the limits of Excel, SAS, and their ilk, there is a next step: learn R or Python.
  • R and Python are the two most popular programming languages used by data analysts and data scientists.
  • Both are free and open source and were developed in the early 1990s — R (an open-source version of the “S” language) for statistical analysis and Python as a general-purpose programming language.
  • For anyone interested in machine learning, working with large datasets, or creating complex data visualizations, both have become standard tools for analysis.
  • Corporate computing offers more data analytics jobs requiring Python.
  • In contrast, in academe, consulting, and finance, R offers an expanded set of data cleaning and analysis tools that are useful in one-off data analysis.
  • Learning either requires a significant time investment—particularly if you have never coded before.
  • Python is better for data manipulation and repeated tasks, while R is good for ad hoc analysis and exploring datasets.

Python

  • Python tends to be in demand in companies run by computer scientists and with a code base, partly because it is easy to learn once you know other languages.
  • Python is most useful for relatively routine, predictable processes.
  • From pulling data, to running automated analyses over and over, to producing visualizations like maps and charts from the results, Python is the better choice.

R

  • R tends to be in demand in consulting fields where every report is ad hoc.
  • Neither is a particularly efficient language from a purely operational standpoint; for that you would turn to C++.
  • Over the past 5 years there has been substantial competition in offerings of interactive development environments (IDEs) to promote the use of either language.
  • The R IDE is called RStudio and is managed by J.J.Allaire (originally from South Bend, IN, and who developed the ColdFusion web development software many years ago).
  • 最近はPosit社が開発しているPositoronが注目されている。

R!

  • R is good for statistics-heavy projects and one-time analyses of a dataset.
  • R is also more difficult to learn, as many of its conventions assume you have a solid background in statistics.
  • Python conceptually uses the same control structures and data types that you will find in other languages, which is why computer scientists prefer Python.

Reporting with R

  • No matter how brilliant your analyses are, if you cannot communicate them, they are worthless.
  • Report writing, publication on webs, GitHub, and other outlets are all essential parts of being a data analyst.
  • In support of this, R has the report writing tool called knitr.
  • Though not particularly well suited for exploratory analysis, knitr is a powerful tool for dynamic data report generation so much so that it is a worthy addition to any programmer’s toolbox.

R and knitr

  • For example, assume you have a CSV file with some entries that you want to present to someone (or yourself) in some graphical way on regular basis.
  • You can open it in Excel, add a pivot table and graphs; but assume then that you need to combine this data with one or more XML files and some more data in a database—this becomes a scripting task.
  • Excel can still help, but it would be laborious.
  • Python can also accomplish this, but you will need to learn quite a few libraries before you are ready.
  • knitr and R Markdown can easily generate PDF reports with all the graphical and data-processing tools of R included.

R and ML

  • Additionally, R segues statistics with machine learning, which is important since the concepts of machine learning and artificial intelligence derive from statistics.
  • Much of the Python-based literature on machine learning completely misses underlying statistical concepts and consequently fails to be as effective as R in developing machine learning algorithms.
  • It is written by computer scientists who understand well the Python scientific stack, and who will demonstrate the steps in rote manner of how to achieve a certain goal, but would not be able to impart much insight into what happens behind the scenes.

R and AI

  • If you are planning to work in machine learning, R is a much more worthwhile investment than Python.

  • The preceding are some of my admittedly biased opinions.

  • I think R is the better language; but with the caveat that “your mileage may vary” and you should choose your own path.

  • I firmly believe, though, that the extra effort in learning R will be rewarded tenfold if you intend to work in data analytics.

The Roots of Modern Financial Accounting and Auditing

  • Accounting and auditing are ancient, with many modern practices that are rooted in traditions that date back millennia.

  • This section details the evolution of accounting, with explanations of how historical developments live on in idiosyncrasies of accounting and auditing today.

  • (in this class, this section is not covered)

Al-Khwarizmi Algebra of Double-Entry

  • In the Islamic world, the word account took on religious significance, relating to one’s obligation to account to God on all matters pertaining to human endeavor.
  • According to the Qur’an, followers are required to keep records of their indebtedness.
  • Thus Islam provides general approval and guidelines for the recording and reporting of transactions.
  • Clearly this requires ratios, multiplication, and division that were well beyond the scope of Roman numerals and abaci.
  • The complexity of Islamic inheritance law served as an impetus behind the development of algebra by medieval Islamic mathematicians.

  • Al-Khwarizmis “The Compendious Book on Calculation by Completion and Balancing” devoted a chapter on the solution to the Islamic law of inheritance using linear equations.

  • In 15th century, Latin translations of al.Khwarizmis “Book of Addition and Subtraction According to the Hindu Calculation” on the use of Indian numerals, introduced the decimal positional number system to the Western world.

  • Al-Khwarizm (Latinized as Algorithmi from which we derived the word “algorithm”) introduced algebra (from the Arabic al-jabr meaning “restoration”) to accounting, leading to three fundamental accounting -− algebreic concepts

3 Fundamental Accounting-Algebraic Concepts

  1. Debits = Credits : The “Bookkeeping equation” for error control, which is the accounting equivalent of algebraic manipulations on the left-hand and right-hand side of an equation.
  2. Assets = Liabilities + Owner’s Equity : “Real” accounts for tracking wealth, and the “basic accounting equation.” An elaborate form of this equation is presented in a balance sheet that lists all assets, liabilities, and equity, as well as totals to ensure that it balances.
  3. Closing process where “Nominal” accounts for tracking activity are closed to Owner’s Equity : Closing out these accounts at year end yields the net income (the owner’s increment in wealth) — arguably the most important single statistic produced in the accounting process.
  • Algebra manipulates formulas around an equal sign, the only constraint being the formula on the right of the equal sign must have the same value as the formula on the left.
  • Double-entry bookkeeping manipulates debit and credit balances around an equal sign, the only constraint being that the debits must have the same value as the credits.
  • Accounting is applied algebra.
  • Though not specific in this regard, Al-Khwarizmis book hinted at what were to become the standards for later accounting:
    • error control (through double-entry),
    • nominal accounts (which appear on the Income Statement) and
    • real accounts (which appear on the Balance Sheet).
  • Nominal accounts are revenue or expense accounts that are closed to a zero balance at the end of each accounting period.
  • They start with a zero balance at the beginning of a new accounting period, accumulate balances during the period, and return to zero at the year end by means of closing entries.
  • Nominal accounts are income statement accounts and are also called “temporary accounts” in contrast to balance sheet (asset, liability, and owners’ equity) accounts that are called “permanent accounts” or “real accounts.”
  • Real accounts are asset, liability, reserve, and capital accounts that appear on a balance sheet.
  • The balances of real accounts are not canceled out at the end of an accounting period but are carried over to the next period.

Al-Khwarizmis method

  • Al-Khwarizmis method was an immediate hit and was widely disseminated throughout the educated world.
  • we skip this section.

The Renaissance

  • For two centuries, during the rise of the great Italian banking centers of Genoa, Florence, and Venice, Italian banking recorded transactions, made loans, issued scripts, and carried on with numerous other financial activities that we would recognize today.
  • Initially they used single-entry recording (date, and account affected), but this proved error prone as transaction volume increased.
  • Fibbonaci’s Liber Abbaci was widely read, and influential.
  • Giovanni di Bicci de’ Medici introduced double-entry bookkeeping for the Medici bank in the fourteenth century.
  • By the end of the fifteenth century, merchant ventures in Venice used this system widely.
  • The fifteenth century also saw the invention of the printing press in Germany, and affordable, widely available reading glasses from Venetian glassmakers.
  • Leo X’s Vatican was an enthusiastic customer, where printing presses were used to churn out indulgences, and subsequently, Italy became a center of printing, book publishing, and literature.
  • One of the first great texts on mathematics was published by a close friend of Leonardo da Vinci, Venetian Luca Pacioli, in 1494.
  • Summa de Arithmetica, Geometria, Proportioni et Proportionalita (Everything About Arithmetic, Geometry and Proportion) formally described the widely used but still controversial system of double-entry for a much wider audience.

スンマ(スムマ)

算術、幾何、比および比例に関する全集』(スムマ)の初版本は、100冊ほど現存するといわれている。日本では、大阪学院、大阪商業、神奈川大、久留米大、慶應、神戸大学、専修大、日大、広島修道大、早稲田の図書館に蔵書がある(wikipediaより)。

Summa
  • Pacioli’s Summa included one chapter titled, Details of Accounting and Recording that popularized the Method of Venice for accounting.
  • Pacioli’s Summa described the components of bookkeeping as: a memorandum book(日記帳), journal(仕訳帳), and ledger(元帳), with the journal and ledger similar to modern equivalents.
  • A trial balance(試算表) was used when the books were closed.
  • The profit or loss was entered into the capital account to balance the balance sheet.

Summa

  • Thanks to Gutenberg’s printing press, Summa was published throughout Europe.
  • Pacioli’s Summa was translated into the most commonly read vernaculars in Europe and was influential not only in investment and merchant ventures but in accounting in the great estates of Europe.
  • Over the next 400 years it became the standard, in only slightly modi.ed form, for accounting in all realms of business in Europe.

The Birth of Modern Auditing

  • At the start of the 19th century, eleven Londoners listed their occupation as the archaic “Accomptants.”
  • As industry, mass transportation and capital markets expanded so did the need for accountants. Business regulation increased, and industry was often taxed heavily, promoting the need for professionals. The Bankruptcy Act of 1831 allowed accountants to be appointed “Official Assignees,” the first government recognition of the new profession.
  • A primary role became the preparation of accounts and the balance sheet of public companies.
  • Bankrupt firms were especially likely to use their services, which increasingly served an audit function.

Audit firms

  • The British Companies Act of 1844 established the incorporation of business by a formal registration process.
  • It required annual appointment of auditors to examine the accounts and balance sheet of all public companies (the role of accountants under the British Companies Act would change substantially over the century).
  • The Companies Act of 1862 required banks to be audited and established the practice of limited cash dividends to be paid only out of profits. By 1900, the audit was the central practice of accountants.

The Big Six

  • The earliest of the Big Six accounting firms were started in mid-nineteenth century London.
  • William Deloitte opened a London firm in 1845.
  • Samuel Price and Edwin Waterhouse formed their partnership in 1849.
  • William Cooper started his firm in 1854, to be joined by his brothers in 1861. William Peat (KPMG創設者の1人) started in 1867.
  • These men were active in establishing the Institute of Accounting in the 1870s, and a royal charter was granted in 1880.
  • With the Institute and professional requirements to become Chartered Accountants, the profession of accountants was firmly established.

Emerging Technologies and Intangible Assets

  • Information technology plays a pivotal role in audit today.
  • Financial audits are critical mechanisms ensuring the integrity of information systems and the reporting of organizational finances.
  • Expanding audit challenges have fueled a growth market in auditing throughout the past decade.
  • Both undergraduate and graduate accounting enrollments are at their highest level in the past 40 years, with accounting students making up 40% of business school enrollments (Fig. 1).
  • Graduate degrees are increasingly important to the profession, around 40% of accounting graduates hired by public accounting firms have graduate degrees.
  • The second largest group and hired into public accounting had degrees in information technology and computer science.
  • The most prestigious of the accounting firms, the largest accounting firms, the Big Four, have increased their intake substantially (Table 1).
  • The financial information sector of the USA and world economies are major contributors to jobs’ growth and wealth.
  • In 2018, it represented around 15% of the US economy (about 2 trillion dollars) and around 10% of the global economy (around 7 trillion dollars).
  • In addition to accounting firms, large banks, rating agencies, funds, private investment, and many other fields require accounting expertise to function competitively in current markets.
  • Increasingly that means expertise in information technologies as well.

Financial Accounting

  • Accountancy is the process of communicating financial information about a business entity to users such as shareholders and managers.
  • The communication is generally in the form of financial statements that show, in money terms, the economic resources under the control of management; the art lies in selecting the information that is relevant to the user and is reliable.
  • The principles of accountancy are applied to business entities in three divisions of practical art, named accounting, bookkeeping, and auditing.
  • Accounting is defined by the American Institute of Certified Public Accountants (AICPA) as “the art of recording, classifying, and summarizing in a significant manner and in terms of money, transactions and events which are, in part at least, of financial character, and interpreting the results thereof.
  • Accounting is called “the language of business” because it is the vehicle for reporting financial information about a business entity to many different groups of people.

Management Accounting

  • Accounting that concentrates on reporting to people inside the business entity is called management accounting and is used to provide information to employees, managers, owner-managers, and auditors.
  • Management accounting is concerned primarily with providing a basis for making management or operating decisions.

Financial Accounting

  • Accounting that provides information to people outside the business entity is called financial accounting and provides information to present and potential shareholders, creditors such as banks or vendors, financial analysts, economists, and government agencies.
  • Because these users have different needs, the presentation of financial accounts is very structured and subject to many more rules than management accounting.
  • The body of rules that governs financial accounting in a given jurisdiction is called GAAP.

19th Century Developments

  • Accounting standards have historically been set by the American Institute of Certified Public Accountants (AICPA) subject to Securities and Exchange Commission regulations.
  • The AICPA first created the Committee on Accounting Procedure in 1939 and replaced that with the Accounting Principles Board in 1951.
  • In 1973, the Accounting Principles Board was replaced by the Financial Accounting Standards Board (FASB) under the supervision of the Financial Accounting Foundation with the Financial Accounting Standards Advisory Council serving to advise and provide input on the accounting standards.

20th Century Developments

  • In 2008, the FASB issued the FASB Accounting Standards Codification, which reorganized the thousands of US GAAP pronouncements into roughly 90 accounting topics.
  • In 2008, the Securities and Exchange Commission issued a preliminary “roadmap” that may lead the USA to abandon Generally Accepted Accounting Principles in the future and to join more than 100 countries around the world instead of using the London-based International Financial Reporting Standards.
  • The SEC expressed their aim to fully adopt International Financial Reporting Standards in the USA by 2014.

The Products of Accounting: Financial Statements

There are four main financial statements.

  1. Balance sheets
  2. Income statements
  3. Cash flow statements
  4. Statements of shareholders’ equity.
  • Balance sheets show what a company owns and what it owes at a fixed point in time.
  • Income statements show how much money a company made and spent over a period of time.
  • Cash flow statements show the exchange of money between a company and the outside world also over a period of time.
  • Statement of shareholders’ equity shows changes in the interests of the company’s shareholders over time.

The Balance Sheet

A balance sheet provides detailed information about a company’s assets, liabilities, and shareholders’ equity.

Assets

  • Assets : company owns that have value.
    • This typically means they can either be sold or used by the company to make products or provide services that can be sold.
    • Assets include physical property.
    • It also includes things that cannot be touched but nevertheless exist and have value.

Liabilities

  • Liabilities are amounts of money that a company owes to others.
    • This can include all kinds of obligations, like money borrowed from a bank to launch a new product, rent for use of a building, money owed to suppliers for materials, payroll a company owes to its employees, environmental cleanup costs, or taxes owed to the government.
    • Liabilities also include obligations to provide goods or services to customers in the future.

Shareholders’ Equity

  • Shareholders’ equity is sometimes called capital or net worth.
    • It is the money that would be left if a company sold all of its assets and paid off all of its liabilities.
    • This leftover money belongs to the shareholders, or the owners, of the company.

A company’s balance sheet is set up like the basic accounting equation.

Assets = Liabilities + Shareholders' Equity

On the left side of the balance sheet, companies list their assets. On the right side, they list their liabilities and shareholders’ equity.

Current and Noncurrent Assets and Liabilities

  • Assets are generally listed based on how quickly they will be converted into cash.
  • Current assets are things a company expects to convert to cash within 1 year.
  • Noncurrent assets are things a company does not expect to convert to cash within 1 year or that would take longer than 1 year to sell.
  • Liabilities are generally listed based on their due dates.
  • Liabilities are said to be either current or long term.
  • Current liabilities are obligations a company expects to pay off within the year.
  • Long-term liabilities are obligations due more than 1 year away.
  • Shareholders’ equity is the amount owners invested in the company’s stock, plus or minus the company’s earnings or losses since inception.
  • Sometimes companies distribute earnings, instead of retaining them.
  • These distributions are called dividends.
  • A balance sheet shows a snapshot of a company’s assets, liabilities, and shareholders’ equity at the end of the reporting period.
  • It does not show the flows into and out of the accounts during the period.

The Income Statement

  • An income statement is a report that shows how much revenue a company earned over a specific time period.
  • An income statement also shows the costs and expenses associated with earning that revenue.
  • The literal “bottom line” of the statement usually shows the company’s net earnings or losses.
  • Income statements also report ‘EPS’.
  • This calculation tells you how much money shareholders would receive if the company decided to distribute all of the net earnings for the period.

Cash Flow Statements

  • Cash flow statements report a company’s inflow and outflow of cash.
  • This is important because a company needs to have enough cash on hand to pay its expenses and purchase assets.
  • While an income statement can tell you whether a company made a profit, a cash flow statement can tell you whether the company generated cash.
  • Cash Flow Statements may be generalized to Working Capital Statements, which replace cash in the calculations, with more general Current Assets and Current Liabilities, both of which are expected to expire within the operating cycle (typically 1 year) and thus are what would be called “near-cash.”
  • The bottom line of the cash flow statement shows the net increase or decrease in cash for the period.

Cash flow statements are divided into three main parts. Each part reviews the cash flow from one of three types of activities:

  1. operating activities
  2. investing activities
  3. financing activities

The Methodology of Accounting

  • Financial accounting is the vehicle through which firms can record and report important economic transactions that affect their wealth.
  • It is a quasi-axiomatic system where fundamental “principles” are loosely applied to the recording of economic events (transactions) that affect firm wealth.
  • These detailed transactions are summarized into accounts based on a firm-specific classification called the Chart of Accounts.
  • The accounts are further organized and summarized for reporting in accordance with generally accepted accounting principles (GAAP).
  • The accounting perspective in practice today derives from al-Khwarizmi’s eighth century system of algebraic balancing and arithmetic manipulation.
  • The system is inherently linear—prices and costs are assumed to be additive and generally are considered fixed across transactions.
  • But in practice, many economic processes are non-linear and data may be incomplete and inaccurate.
  • Consequently, modern accounting reports are economic approximations that are made to facilitate tractability and scalability in accounting systems.
  • The perspective adopted by modern auditors reects trade-offs made in accounting reports, and many standard audit procedures accommodate the inherent uncertainty of financial accounting.

The Accounting Process and Major Document Files

Code and Data Repositories for Audit Analytics

後半戦 第4限

R Packages Required for This Book

  • The code requires R packages that are specified in the library("package_name") commands.
  • To install tidyverse package, type install.packages("tidyverse") and then press the Enter/Return key.
  • To load the previously installed package, type library(tidyverse).
  • These will be packages such as tidyverse and keras.

Keras

  • Keras is the API for the Tensorflow machine learning language and requires a separate keras installation with install_keras; general notes on Tensorflow installation are provided below.
  • Tensorflow itself is a collection of algorithms written in multiple languages inside a Python wrapper.
  • It requires a Python environment be installed; further information can be found at https://www.tensorflow.org/.
  • Tensorflow Installation Tensorflow is a machine learning package used in this book; commands to Tensorflow are called using the Keras API.

TensorFlow

You can also choose to install TensorFlow manually (as described at https://www.tensorflow.org/install/). TensorFlow for R is tested and supported on the following 64-bit systems:

  1. install the tensorflow R package from GitHub or the CRAN repository.
  2. use the install_tensorflow() function to install TensorFlow.

Installation

You can confirm that the installation succeeded with:

This will provide you with a default installation of TensorFlow suitable for use with the tensorflow R package. There is much more to Tensorflow, and interested readers should review the materials at https://tensorflowfirstudio.com/ and at https:// www.tensorflow.org/.

A caveat on code ’copy & paste’

  • Though code from this book is available in the package repositories, readers may be tempted in some situations to ’copy and paste’ code directly from the book.
  • Unfortunately, many built-in machine editors try to convert quotation marks to distinct opening and closing forms, which will cause the resulting code to throw an error.
  • Be aware that ‘copy & paste’ code may require some additional editing.

R 入門

Rとは

  • Rは統計解析やデータ処理のためのプログラミング言語
  • いくつかのパッケージ、関数、データ構造を覚えればすぐに使える
  • データの読み込み、加工、可視化、分析、報告まで一貫して使える
  • データ分析のためのプログラミング言語として最も広く使われている

まず使ってみよう

電卓のように使ってみましょう。

利点:関数化

プログラミングをするメリットの1つは関数化です。

関数として定義しておけば、何度も使いまわすことができます。

利点:繰り返し処理

サイコロを10回振って,出た目の平均を計算する,という処理を10回繰り返す。

利点:分岐処理

条件によって処理を変えることもできます。 先ほどのサイコロの例で、平均値が3.5より大きい場合は「大きい」と表示する。

エクササイズ

サイコロの出た目の平均値は,理論的には \frac{1+2+3+4+5+6}{6} = 3.5

となりますが,実際にサイコロをたくさん降ると平均値が3.5になるか確認してください。

CUIとGUI

  • CUI (Character User Interface) : 文字だけで操作するインターフェース
  • GUI (Graphical User Interface) : グラフィカルなインターフェース

CUIはコマンドを覚える必要があるけれど、マウスのクリックとは異なり、書いておけばいつでも再現できる。 再現性がデータ分析で非常に重要なので、クリックがメインのアプリケーションは使わない。

RStudioやVS Code

  • とはいえ、コマンドを覚えるのは大変なので、RStudioやVS Codeのような統合開発環境を使うと便利です。
  • あとは、MicrosoftのCopilotなどのAIがコードを書いてくれるツールもあります。
  • Github CopilotがVS CodeやRsudioで使えるようになるととても便利です。

Rの実行環境

  1. 自分のPCにRなどをインストールする方法
  • ネット環境がなくても使える
  • いろいろインストールしなきゃならない
  1. Posit CloudやGoogle Colarabolatoryを使う方法
  • インストール不要
  • ネットに繋げないと使えない

こだわりがなければ、Posit Cloudを使うのが一番簡単