Skip to content

Commit 2853723

Browse files
committed
updated documentation
1 parent 8ba4c99 commit 2853723

25 files changed

+130
-157
lines changed

R/GameDay.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#'
33
#' @description Convenience class for dealing with MLBAM GameDay files
44
#'
5-
#' @details Each gameId corresponds to one object of class 'gameday'
5+
#' @details Each gameId corresponds to one object of class \code{\link{gameday}}
66
#'
77
#' @param gameId A valid MLBAM gameId
88
#' @param ... currently ignored
99
#'
10-
#' @return An object of class 'gameday', which consists of a list containing
10+
#' @return An object of class \code{\link{gameday}}, which consists of a list containing
1111
#' \item{gameId}{The ID of the game (e.g. 'gid_2012_08_12_atlmlb_nynmlb_1')}
1212
#' \item{base}{The base URL for the game (e.g. 'http://gd2.mlb.com/components/game/mlb/year_2012/month_08/day_12/')}
1313
#' \item{url}{A character vector containing the names of the XML files downloaded from the GameDay server}

R/GameDayPlays.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ utils::globalVariables("event")
33
#' @title GameDayPlays
44
#' @aliases GameDayPlays-class
55
#'
6-
#' @description Contains the output from \code{\link{getData}}
6+
#' @description A data set that contains play-by-play information returned by \code{\link{getData}}
77
#'
8-
#' @format A \code{\link{GameDayPlays}} object. This is a \code{tbl_df} and
9-
#' \code{data.frame} with 62 columns. The columns are as follows:
8+
#' @format A \code{\link{GameDayPlays}} object. This is a \code{\link{tbl_df}} and
9+
#' \code{\link{data.frame}} with 62 columns. The columns are as follows:
1010
#' \describe{
1111
#' \item{pitcherId}{The MLBAM id of the pitcher}
1212
#' \item{batterId}{The MLBAM id of the batter}
@@ -202,9 +202,9 @@ plot.GameDayPlays = function(x, batterName = NULL, pitcherName = NULL, events =
202202
#'
203203
#' @description Summarize MLBAM data
204204
#'
205-
#' @details Prints information about the contents of an object of class 'GameDayPlays'
205+
#' @details Prints information about the contents of an object of class \code{\link{GameDayPlays}}
206206
#'
207-
#' @param object A 'GameDayPlays' data set
207+
#' @param object A \code{\link{GameDayPlays}} data set
208208
#' @param ... currently ignored
209209
#'
210210
#' @return NULL
@@ -225,9 +225,9 @@ summary.GameDayPlays = function(object, ...) {
225225
#'
226226
#' @description Summarize MLBAM data
227227
#'
228-
#' @details Tabulates Lahman-style statistics by team for the contents of a 'GameDayPlays' data set.
228+
#' @details Tabulates Lahman-style statistics by team for the contents of a \code{\link{GameDayPlays}} data set.
229229
#'
230-
#' @param data An object of class 'GameDayPlays'
230+
#' @param data An object of class \code{\link{GameDayPlays}}
231231
#'
232232
#' @return A data.frame of seasonal totals for each team
233233
#'

R/GameDayPlaysExt.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' @title GameDayPlaysExt
22
#'
3-
#' @description Contains the output from makeWAR()
3+
#' @description Contains the output from \code{\link{makeWAR}}
44
#'
55
#' @exportClass GameDayPlaysExt
66
#' @examples showClass('GameDayPlaysExt')

R/fieldingplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' \code{\link{contourplot}}.
1414
#' @param y y-coordinate for default method passed to \code{\link{contourplot}}.
1515
#' @param z z-coordinate for default method passed to \code{\link{contourplot}}.
16-
#' @param data a GameDayPlays dataset
16+
#' @param data a \code{\link{GameDayPlays}} dataset
1717
#' @param label a string to be used in the resulting filename
1818
#' @param write.pdf a \code{logical} indicating whether to write the contourplot
1919
#' to a file

R/getData.R

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#' @title getData
22
#'
3-
#' @description Retrieves MLBAM GameDay files for a specified time interval using multiple calls of the gameday function.
3+
#' @description Retrieves MLBAM GameDay files for a specified time interval using
4+
#' multiple calls of the \code{\link{gameday}} function.
45
#'
5-
#' @details Given a beginning and end date, this function will retrieve all data from the MLABM
6-
#' GameDay server in the specified interval and process them into a single data.frame.
6+
#' @details Given a beginning and end date, this function will retrieve all data from the MLBAM
7+
#' GameDay server in the specified interval and process them into a single data frame.
78
#'
8-
#' @param start A valid date in yyyy-mm-dd format (default is \code{Sys.Date() - 1} (i.e. yesterday))
9+
#' @param start A valid date in yyyy-mm-dd format (default is \code{\link{Sys.Date}() - 1} (i.e. yesterday))
910
#' @param end A valid date in yyyy-mm-dd format (default is \code{NULL}, which then uses the same value as \code{start} (i.e. yesterday))
1011
#' @param gameIds a vector of specific gameIds that you want to retrieve. If
1112
#' NULL (the default), then the dates are used to fetch the relevant gameIds
1213
#' @param drop.suspended Logical indicating whether games with fewer than 5 innings should be excluded. Default is \code{TRUE}.
1314
#'
14-
#' @return A data.frame of class 'GameDayPlays' consisting of play-by-play data
15+
#' @return A \code{\link{tbl_df}} of class \code{\link{GameDayPlays}} consisting of play-by-play data
1516
#'
1617
#' @import dplyr
1718
#'
@@ -61,23 +62,13 @@ getData <- function(start = Sys.Date() - 1, end = NULL, gameIds = NULL, drop.sus
6162
}
6263

6364

64-
#' @title getDataMonthly
65-
#'
66-
#' @description Retrieves MLBAM GameDay files for a single month
67-
#'
68-
#' @details Given a year and month, this function will retrieve data from the
69-
#' GameDay server from the specified month and process them into a single data.frame.
70-
#'
65+
#' @rdname getData
7166
#' @param yyyy A year
7267
#' @param m A numeric value corresponding to a month
73-
#'
74-
#' @return A data.frame of class 'GameDayPlays' consisting of play-by-play data
75-
#'
7668
#' @export
77-
#' @export getDataMonthly
7869
#' @examples
7970
#'
80-
#' #Retrieve all of the MLBAM data from May 2013
71+
#' # Retrieve all of the MLBAM data from May 2013
8172
#' \dontrun{
8273
#' # ds = getDataMonthly(2013, 5)
8374
#' }
@@ -88,22 +79,11 @@ getDataMonthly <- function(yyyy = 2013, m = 5) {
8879
return(getData(start, end))
8980
}
9081

91-
#' @title getDataWeekly
92-
#'
93-
#' @description Retrieves MLBAM GameDay files for a single week
94-
#'
95-
#' @details Given a date, this function will retrieve data from the week starting on the specified date from the
96-
#' GameDay server and process them into a single data.frame.
97-
#'
98-
#' @param start A valid date in yyyy-mm-dd format (default Sys.Date()-8)
99-
#'
100-
#' @return A data.frame of class 'GameDayPlays' consisting of play-by-play data
101-
#'
82+
#' @rdname getData
10283
#' @export
103-
#' @export getDataWeekly
10484
#' @examples
10585
#'
106-
#' #Retrieve all the data from the first week of the 2013 season
86+
#' # Retrieve all the data from the first week of the 2013 season
10787
#' \dontrun{
10888
#' ds = getDataWeekly('2013-03-31')
10989
#' }
@@ -160,7 +140,7 @@ getGameIds <- function(date = Sys.Date()) {
160140
#' @param data a data.frame returned by \code{\link{getData}}
161141
#' @param ... currently ignored
162142
#'
163-
#' @return A data.frame of class 'GameDayPlays' consisting of play-by-play data
143+
#' @return A data.frame of class \code{\link{GameDayPlays}} consisting of play-by-play data
164144
#'
165145
#' @export
166146
#' @examples

R/makeWAR.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' @title makeWAR
22
#' @aliases makeWAR.GameDayPlays
33
#'
4-
#' @description Computes runs above average (RAA) for each player involved in each play of the 'GameDayPlays' object.
4+
#' @description Computes runs above average (RAA) for each player involved in each play of the \code{\link{GameDayPlays}} object.
55
#'
6-
#' @details Within a 'GameDayPlays' object, each row consists of a single plate appearance and contains information about the batter, all of the baserunners,
6+
#' @details Within a \code{\link{GameDayPlays}} object, each row consists of a single plate appearance and contains information about the batter, all of the baserunners,
77
#' the pitcher, and all of the fielders on the field during the plate appearance. The total value of the play as determined by the change in the run expectancy
88
#' matrix from the beginning of the plate appearence to the end of the plate appearance is partitioned across all players involved in the play on offense,
99
#' and that same value (with the opposite sign) is partitioned across the pitcher and all of the fielders. Thus for every single plate appearance a runs above average (RAA) value is assigned
@@ -28,20 +28,20 @@
2828
#' must be 'batterPos' (the defensive position of the batter)}
2929
#' }
3030
#'
31-
#' @param data An object of class 'GameDayPlays'
31+
#' @param data An object of class \code{\link{GameDayPlays}}
3232
#' @param models A named list of models, each with a predict() method. See Details.
3333
#' @param verbose A \code{logical} indicating whether you want various messages
3434
#' and information to be displayed during the computation
3535
#' @param low.memory A \code{logical} indicating whether to conserve memory by
3636
#' not storing the model objects.
3737
#' @param ... currently ignored
3838
#'
39-
#' @return An object of class 'openWARPlays' which is a list of length 4 containing the following:
39+
#' @return An object of class \code{\link{openWARPlays}} which is a list of length 4 containing the following:
4040
#' \itemize{
41-
#' \item{plays}{A data.frame of class 'GameDayPlays' that is the same as the input to the function.}
42-
#' \item{data}{A data.frame of class 'GameDayPlaysExt' containing the original data along with appended rows containing the RAA values for each player involved in a plate appearance}
41+
#' \item{plays}{A data.frame of class \code{\link{GameDayPlays}} that is the same as the input to the function.}
42+
#' \item{data}{A data.frame of class \code{\link{GameDayPlaysExt}} containing the original data along with appended rows containing the RAA values for each player involved in a plate appearance}
4343
#' \item{models.used}{A list containing all of the model information for each of the models used in computing RAA.}
44-
#' \item{openWAR}{A data.frame of class 'openWARPlays' containing only the columns necessry for input into the getWAR function. }
44+
#' \item{openWAR}{A data.frame of class \code{\link{openWARPlays}} containing only the columns necessry for input into the getWAR function. }
4545
#' }
4646
#'
4747
#' @import dplyr

R/openWARPlays.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ setClass("openWARPlays", contains = "data.frame")
1111
#'
1212
#' @description Tabulates runs above average (RAA) values per player
1313
#'
14-
#' @details Takes an object of class 'openWARPlays' and consolidates the RAA values by player
14+
#' @details Takes an object of class \code{\link{openWARPlays}} and consolidates the RAA values by player
1515
#'
16-
#' @param data An object of class 'openWARPlays'
16+
#' @param data An object of class \code{\link{openWARPlays}}
1717
#' @param ... currently ignored
1818
#'
19-
#' @return A data.frame of class 'openWARPlayers'
19+
#' @return A data.frame of class \code{\link{openWARPlayers}}
2020
#'
2121
#' @import dplyr
2222
#'

R/replacement.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' of a replacement-level player for use in converting runs above average (RAA)
1313
#' into runs above replacement (RAR) and ultimately wins above replacement (WAR).
1414
#'
15-
#' @param data An object of class 'openWARPlays'
15+
#' @param data An object of class \code{\link{openWARPlays}}
1616
#' @param nteams the number of teams used to calculate the number of non-replacement
1717
#' players. The default is 30 since that is the number of MLB teams. (Note: Using 27.5
1818
#' seems to result in a total WAR that is close to 1000.)
@@ -75,7 +75,7 @@ getReplacementPlayers.openWARPlays = function(data, nteams = 30, ...) {
7575
#'
7676
#' @details Returns only the RAA values involving replacement-level players
7777
#'
78-
#' @param data A data.frame of class 'openWARPlays'
78+
#' @param data A data.frame of class \code{\link{openWARPlays}}
7979
#' @param replacementIds A vector of playerIds for replacement-level players
8080
#'
8181
#' @return A list of RAA values for each type of activity that generates RAA values
@@ -126,7 +126,7 @@ getReplacementActivity.openWARPlays = function(data, replacementIds) {
126126
#'
127127
#' @details Identifies replacement level players and then computes their mean contribution
128128
#'
129-
#' @param data A data.frame of class 'openWARPlays'
129+
#' @param data A data.frame of class \code{\link{openWARPlays}}
130130
#' @param replIds MLBAM IDs of specific players that you want to designate as replacement-level
131131
#'
132132
#' @return A numeric vector of mean contributions per activity for replacement-level players

R/shakeWAR.R

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
#' @title shakeWAR
22
#'
3-
#' @description resample a data.frame to obtain variance estimates for WAR
3+
#' @description Resample to obtain variance estimates for WAR
44
#'
5-
#' @details Resamples the rows of an MLBAM data set and calculates WAR values on the re-sampled data set.
6-
#' This process is repeated many times to yield variance estimates of WAR.
5+
#' @details The general idea is to use resampling techniques to compute
6+
#' variance estimates for openWAR. The \code{resample} argument controls
7+
#' how that resampling is done.
8+
#'
9+
#' For \code{resample = 'plays'}, \code{\link{makeWAR}} is run on the actual
10+
#' plays passed in the \code{data} argument, if it hasn't been computed already.
11+
#' The resulting RAA values (for each play) are an estimate of what actually happened.
12+
#' These RAA values are resampled \code{N} times.
13+
#'
14+
#' \code{resample = 'models'} is not currently implemented, but in future versions,
15+
#' this option would allow you to resample the rows of the original data, run
16+
#' \code{\link{makeWAR}} on each resampled data set, collect all of the models
17+
#' generated during that process, and then evaluate the original data using each
18+
#' of the resampled models. This would allow you isolate the modeling error.
19+
#'
20+
#' For \code{resample = 'both'}, the plays are resampled, and \code{\link{makeWAR}}
21+
#' is computed on each resampled data set. Note that this is both computationally
22+
#' and memory intensive.
723
#'
824
#' @param data An object that contains \code{\link{GameDayPlays}} data or data that has already been processed by \code{\link{makeWAR}}.
925
#' @param N the number of resamples (default 10)
1026
#' @param resample An element of \code{c('plays', 'models', 'both')}. Currently only \code{plays}
11-
#' and \code{both} are implemented. Only works with \code{shakeWAR.GameDayPlays} method.
12-
#' @param ... additional arguments passed to \code{shakeWAR} methods
27+
#' and \code{both} are implemented. Only works with \code{\link{shakeWAR.GameDayPlays}} method.
28+
#' @param ... additional arguments passed to \code{\link{shakeWAR}} methods
1329
#'
14-
#' @return a data.frame with RAA values
30+
#' @return a \code{do.\link{openWARPlayers}} data frame with RAA values
1531
#'
1632
#' @export
1733
#'
@@ -20,7 +36,7 @@
2036
#' @examples
2137
#'
2238
#' \dontrun{
23-
#' res = shakeWAR(May, resample='plays', N=5)
39+
#' res <- shakeWAR(May, resample='plays', N=5)
2440
#' summary(res)
2541
#' }
2642
#'

man/GameDayPlays-class.Rd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
\name{GameDayPlays-class}
55
\alias{GameDayPlays-class}
66
\title{GameDayPlays}
7-
\format{A \code{\link{GameDayPlays}} object. This is a \code{tbl_df} and
8-
\code{data.frame} with 62 columns. The columns are as follows:
7+
\format{A \code{\link{GameDayPlays}} object. This is a \code{\link{tbl_df}} and
8+
\code{\link{data.frame}} with 62 columns. The columns are as follows:
99
\describe{
1010
\item{pitcherId}{The MLBAM id of the pitcher}
1111
\item{batterId}{The MLBAM id of the batter}
@@ -73,7 +73,7 @@
7373
Home plate has \code{theta} of 0.}
7474
}}
7575
\description{
76-
Contains the output from \code{\link{getData}}
76+
A data set that contains play-by-play information returned by \code{\link{getData}}
7777
}
7878
\examples{
7979
showClass('GameDayPlays')

0 commit comments

Comments
 (0)