1. Trang chủ
  2. » Công Nghệ Thông Tin

Beginning data science in r

369 117 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewer

  • Acknowledgments

  • Introduction

  • Chapter 1: Introduction to R Programming

    • Basic Interaction with R

    • Using R as a Calculator

      • Simple Expressions

      • Assignments

      • Actually, All of the Above Are Vectors of Values…

      • Indexing Vectors

      • Vectorized Expressions

    • Comments

    • Functions

      • Getting Documentation for Functions

      • Writing Your Own Functions

      • Vectorized Expressions and Functions

    • A Quick Look at Control Structures

    • Factors

    • Data Frames

    • Dealing with Missing Values

    • Using R Packages

    • Data Pipelines (or Pointless Programming)

      • Writing Pipelines of Function Calls

      • Writing Functions that Work with Pipelines

      • The magical “.” argument

      • Defining Functions Using .

      • Anonymous Functions

      • Other Pipeline Operations

    • Coding and Naming Conventions

    • Exercises

      • Mean of Positive Values

      • Root Mean Square Error

  • Chapter 2: Reproducible Analysis

    • Literate Programming and Integration of Workflow and Documentation

    • Creating an R Markdown/knitr Document in RStudio

    • The YAML Language

    • The Markdown Language

      • Formatting Text

      • Cross-Referencing

      • Bibliographies

      • Controlling the Output (Templates/Stylesheets)

    • Running R Code in Markdown Documents

      • Using Chunks when Analyzing Data (Without Compiling Documents)

      • Caching Results

      • Displaying Data

    • Exercises

      • Create an R Markdown Document

      • Produce Different Output

      • Add Caching

  • Chapter 3: Data Manipulation

    • Data Already in R

    • Quickly Reviewing Data

    • Reading Data

    • Examples of Reading and Formatting Datasets

      • Breast Cancer Dataset

      • Boston Housing Dataset

      • The readr Package

    • Manipulating Data with dplyr

      • Some Useful dplyr Functions

        • select(): Pick Selected Columns and Get Rid of the Rest

        • mutate():Add Computed Values to Your Data Frame

        • Transmute(): Add Computed Values to Your Data Frame and Get Rid of All Other Columns

        • arrange(): Reorder Your Data Frame by Sorting Columns

        • filter(): Pick Selected Rows and Get Rid of the Rest

        • group_by(): Split Your Data Into Subtables Based on Column Values

        • summarise/summarize(): Calculate Summary Statistics

      • Breast Cancer Data Manipulation

    • Tidying Data with tidyr

    • Exercises

      • Importing Data

      • Using dplyr

      • Using tidyr

  • Chapter 4: Visualizing Data

    • Basic Graphics

    • The Grammar of Graphics and the ggplot2 Package

      • Using qplot()

      • Using Geometries

      • Facets

      • Scaling

      • Themes and Other Graphics Transformations

    • Figures with Multiple Plots

    • Exercises

  • Chapter 5: Working with Large Datasets

    • Subsample Your Data Before You Analyze the Full Dataset

    • Running Out of Memory During Analysis

    • Too Large to Plot

    • Too Slow to Analyze

    • Too Large to Load

    • Exercises

      • Subsampling

      • Hex and 2D Density Plots

  • Chapter 6: Supervised Learning

    • Machine Learning

    • Supervised Learning

      • Regression versus Classification

      • Inference versus Prediction

    • Specifying Models

      • Linear Regression

      • Logistic Regression (Classification, Really)

      • Model Matrices and Formula

    • Validating Models

      • Evaluating Regression Models

      • Evaluating Classification Models

        • Confusion Matrix

        • Accuracy

        • Sensitivity and Specificity

        • Other Measures

        • More Than Two Classes

      • Random Permutations of Your Data

      • Cross-Validation

      • Selecting Random Training and Testing Data

    • Examples of Supervised Learning Packages

      • Decision Trees

      • Random Forests

      • Neural Networks

      • Support Vector Machines

    • Naive Bayes

    • Exercises

      • Fitting Polynomials

      • Evaluating Different Classification Measures

      • Breast Cancer Classification

      • Leave-One-Out Cross-Validation (Slightly More Difficult)

      • Decision Trees

      • Random Forests

      • Neural Networks

      • Support Vector Machines

      • Compare Classification Algorithms

  • Chapter 7: Unsupervised Learning

    • Dimensionality Reduction

      • Principal Component Analysis

      • Multidimensional Scaling

    • Clustering

      • k-Means Clustering

      • Hierarchical Clustering

    • Association Rules

    • Exercises

      • Dealing with Missing Data in the HouseVotes84 Data

      • Rescaling for k-Means Clustering

      • Varying k

    • Project 1

      • Importing Data

      • Exploring the Data

        • Distribution of Quality Scores

        • Is This Wine Red or White?

    • Fitting Models

    • Exercises

      • Exploring Other Formulas

      • Exploring Different Models

      • Analyzing Your Own Dataset

  • Chapter 8: More R Programming

    • Expressions

      • Arithmetic Expressions

      • Boolean Expressions

    • Basic Data Types

      • The Numeric Type

      • The Integer Type

      • The Complex Type

      • The Logical Type

      • The Character Type

    • Data Structures

      • Vectors

      • Matrix

      • Lists

      • Indexing

      • Named Values

      • Factors

      • Formulas

    • Control Structures

      • Selection Statements

      • Loops

      • A Word of Warning About Looping

    • Functions

      • Named Arguments

      • Default Parameters

      • Return Values

      • Lazy Evaluation

      • Scoping

      • Function Names Are Different from Variable Names

    • Recursive Functions

    • Exercises

      • Fibonacci Numbers

      • Outer Product

      • Linear Time Merge

      • Binary Search

      • More Sorting

      • Selecting the k Smallest Element

  • Chapter 9: Advanced R Programming

    • Working with Vectors and Vectorizing Functions

      • ifelse

      • Vectorizing Functions

      • The apply Family

        • apply

        • lapply

        • sapply and vapply

    • Advanced Functions

      • Special Names

      • Infix Operators

      • Replacement Functions

    • How Mutable Is Data Anyway?

    • Functional Programming

      • Anonymous Functions

      • Functions Taking Functions as Arguments

      • Functions Returning Functions (and Closures)

      • Filter, Map, and Reduce

    • Function Operations: Functions as Input and Output

      • Ellipsis Parameters

    • Exercises

      • between

      • apply_if

      • power

      • Row and Column Sums

      • Factorial Again

      • Function Composition

  • Chapter 10: Object Oriented Programming

    • Immutable Objects and Polymorphic Functions

    • Data Structures

      • Example: Bayesian Linear Model Fitting

    • Classes

    • Polymorphic Functions

      • Defining Your Own Polymorphic Functions

    • Class Hierarchies

      • Specialization as Interface

      • Specialization in Implementations

    • Exercises

      • Shapes

      • Polynomials

  • Chapter 11: Building an R Package

    • Creating an R Package

      • Package Names

      • The Structure of an R Package

      • .Rbuildignore

      • Description

        • Title

        • Version

        • Description

        • Author and Maintainer

        • License

        • Type, Date, LazyData

        • URL and BugReports

        • Dependencies

        • Using an Imported Package

        • Using a Suggested Package

      • NAMESPACE

      • R/ and man/

    • Roxygen

      • Documenting Functions

      • Import and Export

      • Package Scope Versus Global Scope

      • Internal Functions

      • File Load Order

    • Adding Data to Your Package

    • Building an R Package

    • Exercises

  • Chapter 12: Testing and Package Checking

    • Unit Testing

      • Automating Testing

      • Using testthat

      • Writing Good Tests

      • Using Random Numbers in Tests

      • Testing Random Results

    • Checking a Package for Consistency

    • Exercise

  • Chapter 13: Version Control

    • Version Control and Repositories

    • Using git in RStudio

      • Installing git

      • Making Changes to Files, Staging Files, and Committing Changes

      • Adding git to an Existing Project

      • Bare Repositories and Cloning Repositories

      • Pushing Local Changes and Fetching and Pulling Remote Changes

      • Handling Conflicts

      • Working with Branches

      • Typical Workflows Involve Lots of Branches

      • Pushing Branches to the Global Repository

    • GitHub

      • Moving an Existing Repository to GitHub

      • Installing Packages from GitHub

    • Collaborating on GitHub

      • Pull Requests

      • Forking Repositories Instead of Cloning

    • Exercises

  • Chapter 14: Profiling and Optimizing

    • Profiling

      • A Graph-Flow Algorithm

    • Speeding Up Your Code

    • Parallel Execution

    • Switching to C++

    • Exercises

    • Project 2

    • Bayesian Linear Regression

      • Exercises: Priors and Posteriors

        • Sample from a Multivariate Normal Distribution

        • Computing the Posterior Distribution

      • Predicting Target Variables for New Predictor Values

    • Formulas and Their Model Matrix

      • Working with Model Matrices in R

      • Exercises

        • Building Model Matrices

        • Fitting General Models

      • Model Matrices Without Response Variables

      • Exercises

        • Model Matrices for New Data

        • Predicting New Targets

    • Interface to a blm Class

      • Constructor

      • Updating Distributions: An Example Interface

      • Designing Your blm Class

      • Model Methods

        • coefficients

        • confint

        • deviance

        • fitted

        • plot

        • predict

        • print

        • residuals

        • summary

    • Building an R Package for blm

      • Deciding on the Package Interface

      • Organization of Source Files

      • Document Your Package Interface Well

      • Adding README and NEWS Files to Your Package

        • README

        • NEWS

    • Testing

    • GitHub

    • Conclusions

      • Data Science

      • Machine Learning

      • Data Analysis

      • R Programming

    • The End

    • Acknowledgements

  • Index

Nội dung

Beginning Data Science in R Data Analysis, Visualization, and Modelling for the Data Scientist — Thomas Mailund www.allitebooks.com Beginning Data Science in R Data Analysis, Visualization, and Modelling for the Data Scientist Thomas Mailund www.allitebooks.com Beginning Data Science in R: Data Analysis, Visualization, and Modelling for the Data Scientist Thomas Mailund Aarhus, Denmark ISBN-13 (pbk): 978-1-4842-2670-4 DOI 10.1007/978-1-4842-2671-1 ISBN-13 (electronic): 978-1-4842-2671-1 Library of Congress Control Number: 2017934529 Copyright © 2017 by Thomas Mailund This work is subject to copyright All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed Trademarked names, logos, and images may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made The publisher makes no warranty, express or implied, with respect to the material contained herein Managing Director: Welmoed Spahr Editorial Director: Todd Green Acquisitions Editor: Steve Anglin Development Editor: Matthew Moodie Technical Reviewer: Andrew Moskowitz Coordinating Editor: Mark Powers Copy Editor: Kezia Endsley Compositor: SPi Global Indexer: SPi Global Artist: SPi Global Cover image designed by Freepik Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springersbm.com, or visit www.springeronline.com Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance, Inc (SSBM Finance, Inc) SSBM Finance Inc is a Delaware corporation For information on translations, please e-mail rights@apress.com, or visit http://www.apress.com/rightspermissions Apress titles may be purchased in bulk for academic, corporate, or promotional use eBook versions and licenses are also available for most titles For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484226704 For more detailed information, please visit http://www.apress.com/source-code Printed on acid-free paper www.allitebooks.com Contents at a Glance About the Author���������������������������������������������������������������������������������������������������xvii About the Technical Reviewer��������������������������������������������������������������������������������xix Acknowledgments��������������������������������������������������������������������������������������������������xxi Introduction����������������������������������������������������������������������������������������������������������xxiii ■Chapter ■ 1: Introduction to R Programming����������������������������������������������������������� ■Chapter ■ 2: Reproducible Analysis����������������������������������������������������������������������� 29 ■Chapter ■ 3: Data Manipulation������������������������������������������������������������������������������ 45 ■Chapter ■ 4: Visualizing Data��������������������������������������������������������������������������������� 75 ■Chapter ■ 5: Working with Large Datasets����������������������������������������������������������� 113 ■Chapter ■ 6: Supervised Learning������������������������������������������������������������������������ 125 ■Chapter ■ 7: Unsupervised Learning�������������������������������������������������������������������� 169 ■Chapter ■ 8: More R Programming����������������������������������������������������������������������� 205 ■Chapter ■ 9: Advanced R Programming��������������������������������������������������������������� 233 ■Chapter ■ 10: Object Oriented Programming������������������������������������������������������� 257 ■Chapter ■ 11: Building an R Package������������������������������������������������������������������� 269 ■Chapter ■ 12: Testing and Package Checking������������������������������������������������������ 281 ■Chapter ■ 13: Version Control������������������������������������������������������������������������������ 287 ■Chapter ■ 14: Profiling and Optimizing���������������������������������������������������������������� 303 Index��������������������������������������������������������������������������������������������������������������������� 347 iii www.allitebooks.com Contents About the Author���������������������������������������������������������������������������������������������������xvii About the Technical Reviewer��������������������������������������������������������������������������������xix Acknowledgments��������������������������������������������������������������������������������������������������xxi Introduction����������������������������������������������������������������������������������������������������������xxiii ■Chapter ■ 1: Introduction to R Programming����������������������������������������������������������� Basic Interaction with R��������������������������������������������������������������������������������������������������� Using R as a Calculator���������������������������������������������������������������������������������������������������� Simple Expressions�������������������������������������������������������������������������������������������������������������������������������� Assignments������������������������������������������������������������������������������������������������������������������������������������������� Actually, All of the Above Are Vectors of Values…���������������������������������������������������������������������������������� Indexing Vectors������������������������������������������������������������������������������������������������������������������������������������� Vectorized Expressions��������������������������������������������������������������������������������������������������������������������������� Comments������������������������������������������������������������������������������������������������������������������������ Functions�������������������������������������������������������������������������������������������������������������������������� Getting Documentation for Functions����������������������������������������������������������������������������������������������������� Writing Your Own Functions����������������������������������������������������������������������������������������������������������������� 10 Vectorized Expressions and Functions������������������������������������������������������������������������������������������������� 12 A Quick Look at Control Structures�������������������������������������������������������������������������������� 12 Factors��������������������������������������������������������������������������������������������������������������������������� 16 Data Frames������������������������������������������������������������������������������������������������������������������� 18 Dealing with Missing Values������������������������������������������������������������������������������������������ 20 Using R Packages����������������������������������������������������������������������������������������������������������� 21 v www.allitebooks.com ■ Contents Data Pipelines (or Pointless Programming)�������������������������������������������������������������������� 22 Writing Pipelines of Function Calls������������������������������������������������������������������������������������������������������� 23 Writing Functions that Work with Pipelines������������������������������������������������������������������������������������������ 23 The magical “.” argument��������������������������������������������������������������������������������������������������������������������� 24 Defining Functions Using ������������������������������������������������������������������������������������������������������������������ 25 Anonymous Functions�������������������������������������������������������������������������������������������������������������������������� 26 Other Pipeline Operations��������������������������������������������������������������������������������������������������������������������� 27 Coding and Naming Conventions����������������������������������������������������������������������������������� 28 Exercises������������������������������������������������������������������������������������������������������������������������ 28 Mean of Positive Values������������������������������������������������������������������������������������������������������������������������ 28 Root Mean Square Error����������������������������������������������������������������������������������������������������������������������� 28 ■Chapter ■ 2: Reproducible Analysis����������������������������������������������������������������������� 29 Literate Programming and Integration of Workflow and Documentation����������������������� 30 Creating an R Markdown/knitr Document in RStudio���������������������������������������������������� 30 The YAML Language������������������������������������������������������������������������������������������������������� 33 The Markdown Language����������������������������������������������������������������������������������������������� 34 Formatting Text������������������������������������������������������������������������������������������������������������������������������������� 35 Cross-Referencing�������������������������������������������������������������������������������������������������������������������������������� 38 Bibliographies��������������������������������������������������������������������������������������������������������������������������������������� 39 Controlling the Output (Templates/Stylesheets)����������������������������������������������������������������������������������� 39 Running R Code in Markdown Documents��������������������������������������������������������������������� 40 Using Chunks when Analyzing Data (Without Compiling Documents)�������������������������������������������������� 42 Caching Results������������������������������������������������������������������������������������������������������������������������������������ 43 Displaying Data������������������������������������������������������������������������������������������������������������������������������������� 43 Exercises������������������������������������������������������������������������������������������������������������������������ 44 Create an R Markdown Document�������������������������������������������������������������������������������������������������������� 44 Produce Different Output���������������������������������������������������������������������������������������������������������������������� 44 Add Caching����������������������������������������������������������������������������������������������������������������������������������������� 44 vi www.allitebooks.com ■ Contents ■Chapter ■ 3: Data Manipulation������������������������������������������������������������������������������ 45 Data Already in R������������������������������������������������������������������������������������������������������������ 45 Quickly Reviewing Data�������������������������������������������������������������������������������������������������� 47 Reading Data������������������������������������������������������������������������������������������������������������������ 48 Examples of Reading and Formatting Datasets������������������������������������������������������������� 49 Breast Cancer Dataset�������������������������������������������������������������������������������������������������������������������������� 49 Boston Housing Dataset����������������������������������������������������������������������������������������������������������������������� 55 The readr Package�������������������������������������������������������������������������������������������������������������������������������� 56 Manipulating Data with dplyr����������������������������������������������������������������������������������������� 58 Some Useful dplyr Functions���������������������������������������������������������������������������������������������������������������� 59 Breast Cancer Data Manipulation��������������������������������������������������������������������������������������������������������� 65 Tidying Data with tidyr��������������������������������������������������������������������������������������������������� 69 Exercises������������������������������������������������������������������������������������������������������������������������ 72 Importing Data�������������������������������������������������������������������������������������������������������������������������������������� 73 Using dplyr�������������������������������������������������������������������������������������������������������������������������������������������� 73 Using tidyr�������������������������������������������������������������������������������������������������������������������������������������������� 73 ■Chapter ■ 4: Visualizing Data��������������������������������������������������������������������������������� 75 Basic Graphics��������������������������������������������������������������������������������������������������������������� 75 The Grammar of Graphics and the ggplot2 Package������������������������������������������������������ 83 Using qplot()����������������������������������������������������������������������������������������������������������������������������������������� 84 Using Geometries��������������������������������������������������������������������������������������������������������������������������������� 88 Facets��������������������������������������������������������������������������������������������������������������������������������������������������� 97 Scaling������������������������������������������������������������������������������������������������������������������������������������������������ 100 Themes and Other Graphics Transformations������������������������������������������������������������������������������������ 105 Figures with Multiple Plots������������������������������������������������������������������������������������������� 109 Exercises���������������������������������������������������������������������������������������������������������������������� 111 vii www.allitebooks.com ■ Contents ■Chapter ■ 5: Working with Large Datasets����������������������������������������������������������� 113 Subsample Your Data Before You Analyze the Full Dataset������������������������������������������ 113 Running Out of Memory During Analysis���������������������������������������������������������������������� 115 Too Large to Plot����������������������������������������������������������������������������������������������������������� 116 Too Slow to Analyze������������������������������������������������������������������������������������������������������ 120 Too Large to Load��������������������������������������������������������������������������������������������������������� 121 Exercises���������������������������������������������������������������������������������������������������������������������� 124 Subsampling��������������������������������������������������������������������������������������������������������������������������������������� 124 Hex and 2D Density Plots������������������������������������������������������������������������������������������������������������������� 124 ■Chapter ■ 6: Supervised Learning������������������������������������������������������������������������ 125 Machine Learning��������������������������������������������������������������������������������������������������������� 125 Supervised Learning���������������������������������������������������������������������������������������������������� 125 Regression versus Classification�������������������������������������������������������������������������������������������������������� 126 Inference versus Prediction���������������������������������������������������������������������������������������������������������������� 127 Specifying Models�������������������������������������������������������������������������������������������������������� 128 Linear Regression������������������������������������������������������������������������������������������������������������������������������� 128 Logistic Regression (Classification, Really)���������������������������������������������������������������������������������������� 133 Model Matrices and Formula�������������������������������������������������������������������������������������������������������������� 136 Validating Models��������������������������������������������������������������������������������������������������������� 145 Evaluating Regression Models����������������������������������������������������������������������������������������������������������� 145 Evaluating Classification Models�������������������������������������������������������������������������������������������������������� 147 Random Permutations of Your Data���������������������������������������������������������������������������������������������������� 153 Cross-Validation��������������������������������������������������������������������������������������������������������������������������������� 157 Selecting Random Training and Testing Data������������������������������������������������������������������������������������� 159 Examples of Supervised Learning Packages��������������������������������������������������������������� 161 Decision Trees������������������������������������������������������������������������������������������������������������������������������������ 161 Random Forests���������������������������������������������������������������������������������������������������������������������������������� 163 Neural Networks��������������������������������������������������������������������������������������������������������������������������������� 164 Support Vector Machines�������������������������������������������������������������������������������������������������������������������� 165 viii www.allitebooks.com ■ Contents Naive Bayes������������������������������������������������������������������������������������������������������������������ 165 Exercises���������������������������������������������������������������������������������������������������������������������� 166 Fitting Polynomials����������������������������������������������������������������������������������������������������������������������������� 166 Evaluating Different Classification Measures������������������������������������������������������������������������������������� 166 Breast Cancer Classification��������������������������������������������������������������������������������������������������������������� 166 Leave-One-Out Cross-Validation (Slightly More Difficult)������������������������������������������������������������������� 167 Decision Trees������������������������������������������������������������������������������������������������������������������������������������ 167 Random Forests���������������������������������������������������������������������������������������������������������������������������������� 167 Neural Networks��������������������������������������������������������������������������������������������������������������������������������� 167 Support Vector Machines�������������������������������������������������������������������������������������������������������������������� 167 Compare Classification Algorithms����������������������������������������������������������������������������������������������������� 167 ■Chapter ■ 7: Unsupervised Learning�������������������������������������������������������������������� 169 Dimensionality Reduction��������������������������������������������������������������������������������������������� 169 Principal Component Analysis������������������������������������������������������������������������������������������������������������ 169 Multidimensional Scaling������������������������������������������������������������������������������������������������������������������� 177 Clustering��������������������������������������������������������������������������������������������������������������������� 181 k-Means Clustering���������������������������������������������������������������������������������������������������������������������������� 182 Hierarchical Clustering����������������������������������������������������������������������������������������������������������������������� 188 Association Rules��������������������������������������������������������������������������������������������������������� 192 Exercises���������������������������������������������������������������������������������������������������������������������� 196 Dealing with Missing Data in the HouseVotes84 Data������������������������������������������������������������������������ 196 Rescaling for k-Means Clustering������������������������������������������������������������������������������������������������������ 196 Varying k��������������������������������������������������������������������������������������������������������������������������������������������� 196 Project 1����������������������������������������������������������������������������������������������������������������������� 196 Importing Data������������������������������������������������������������������������������������������������������������������������������������ 197 Exploring the Data������������������������������������������������������������������������������������������������������������������������������ 198 Fitting Models��������������������������������������������������������������������������������������������������������������� 203 ix www.allitebooks.com ■ Contents Exercises���������������������������������������������������������������������������������������������������������������������� 204 Exploring Other Formulas������������������������������������������������������������������������������������������������������������������� 204 Exploring Different Models����������������������������������������������������������������������������������������������������������������� 204 Analyzing Your Own Dataset��������������������������������������������������������������������������������������������������������������� 204 ■Chapter ■ 8: More R Programming����������������������������������������������������������������������� 205 Expressions������������������������������������������������������������������������������������������������������������������ 205 Arithmetic Expressions����������������������������������������������������������������������������������������������������������������������� 205 Boolean Expressions�������������������������������������������������������������������������������������������������������������������������� 206 Basic Data Types���������������������������������������������������������������������������������������������������������� 207 The Numeric Type������������������������������������������������������������������������������������������������������������������������������� 207 The Integer Type��������������������������������������������������������������������������������������������������������������������������������� 208 The Complex Type������������������������������������������������������������������������������������������������������������������������������� 208 The Logical Type��������������������������������������������������������������������������������������������������������������������������������� 208 The Character Type����������������������������������������������������������������������������������������������������������������������������� 209 Data Structures������������������������������������������������������������������������������������������������������������ 209 Vectors������������������������������������������������������������������������������������������������������������������������������������������������ 209 Matrix������������������������������������������������������������������������������������������������������������������������������������������������� 210 Lists���������������������������������������������������������������������������������������������������������������������������������������������������� 212 Indexing���������������������������������������������������������������������������������������������������������������������������������������������� 213 Named Values������������������������������������������������������������������������������������������������������������������������������������� 215 Factors������������������������������������������������������������������������������������������������������������������������������������������������ 216 Formulas��������������������������������������������������������������������������������������������������������������������������������������������� 216 Control Structures�������������������������������������������������������������������������������������������������������� 216 Selection Statements������������������������������������������������������������������������������������������������������������������������� 216 Loops�������������������������������������������������������������������������������������������������������������������������������������������������� 218 A Word of Warning About Looping������������������������������������������������������������������������������������������������������ 219 Functions���������������������������������������������������������������������������������������������������������������������� 220 Named Arguments������������������������������������������������������������������������������������������������������������������������������ 221 Default Parameters����������������������������������������������������������������������������������������������������������������������������� 222 Return Values������������������������������������������������������������������������������������������������������������������������������������� 222 x www.allitebooks.com Chapter 14 ■ Profiling and Optimizing To get this version of blm to work you need to get the prior in a form you can pass along to update but if you did the exercises earlier you should already have a function that does this (although you might want to create a class for these distributions and return them as such so you can manipulate them through an interface if you want to take it a bit further) Of course, instead of getting rid of the model fitting code in the body of blm you could also get rid of update and put that functionality in blm by letting that function take a prior parameter If you that, though, you want to give it a default so you can use the original one if it isn’t specified blm

Ngày đăng: 12/04/2019, 00:25