forked from CenterForAssessment/cfaTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f954b0
commit c42621c
Showing
8 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: cfaTools | ||
Version: 0.0-1.992 | ||
Date: 2021-10-22 | ||
Version: 0.0-1.993 | ||
Date: 2021-11-2 | ||
Title: Center for Assessment Tools for Large Scale Educational Assessment Analysis | ||
Description: Center for Assessment developed Tools for Large Scale Educational Assessment. | ||
Authors@R: c(person(given=c("Damian", "W."), family="Betebenner", email="[email protected]", role=c("aut", "cre")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
`getShiftedValues` <- | ||
function( | ||
data_table, | ||
shift_group=c("ID", "CONTENT_AREA"), | ||
shift_period="YEAR", | ||
shift_variable="SCALE_SCORE", | ||
shift_amount=1L, | ||
shift_type="lag") { | ||
|
||
### Utility functions | ||
completeDT <- function(DT, cols, defs = NULL) { | ||
mDT = do.call(CJ, c(DT[, ..cols], list(unique=TRUE))) | ||
res = DT[mDT, on=names(mDT)] | ||
if (length(defs)) | ||
res[, names(defs) := Map(replace, .SD, lapply(.SD, is.na), defs), .SDcols=names(defs)] | ||
res[] | ||
} | ||
|
||
data_table[,FILTER_VARIABLE:=seq.int(dim(data_table)[1])] | ||
data_table_complete <- completeDT(data_table[,c("FILTER_VARIABLE", shift_period, shift_group, shift_variable), with=FALSE], cols=c(shift_period, shift_group)) | ||
setkeyv(data_table_complete, c(shift_group, shift_period)) | ||
data_table_complete[, paste(shift_variable, toupper(shift_type), shift_amount, sep="_") := shift(get(shift_variable), n=shift_amount, type=shift_type), by=shift_group] | ||
data_table_complete <- data_table_complete[!is.na(FILTER_VARIABLE)] | ||
setkeyv(data_table_complete, "FILTER_VARIABLE") | ||
data_table[,paste(shift_variable, toupper(shift_type), shift_amount, sep="_") := data_table_complete[, paste(shift_variable, toupper(shift_type), shift_amount, sep="_"), with=FALSE]] | ||
return(data_table[,FILTER_VARIABLE:=NULL]) | ||
} ### END getShiftedValues function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
\name{getShiftedValues} | ||
\alias{getShiftedValues} | ||
\title{Function for creating lagged/leading value variables from LONG data} | ||
\description{Function for creating lagged/leading value variables from LONG data. | ||
} | ||
\usage{ | ||
getShiftedValues( | ||
data_table, | ||
shift_group=c("ID", "CONTENT_AREA"), | ||
shift_period="YEAR", | ||
shift_variable="SCALE_SCORE", | ||
shift_amount=1L, | ||
shift_type="lag") | ||
} | ||
|
||
\arguments{ | ||
\item{data_table}{Data table to add lagged/leading variable(s) to. | ||
} | ||
\item{shift_group}{Variable(s) indicating groups for which to create lagged/leading variables for. | ||
} | ||
\item{shift_period}{Variable indicating what period the lagged/leading shift occurs relative to. | ||
} | ||
\item{shift_variable}{Variable that lagged/leading values are derived from. | ||
} | ||
\item{shift_amount}{Number of period(s) that the shift_variable is shifted relative to the shift_period. | ||
} | ||
\item{shift_type}{Either "lag" or "lead". | ||
} | ||
} | ||
|
||
|
||
\details{Typical use of the function is to create prior scale score for students from a LONG formatted longitudinal file. | ||
} | ||
|
||
\value{Function returns the submitted \code{data_table} and appends additional variables with suffixes added to the \code{shift_variable} name. For example \code{SCALE_SCORE_LAG_1}. | ||
} | ||
|
||
\author{Damian W. Betebenner \email{dbetebenner@nciea.org} } | ||
|
||
\examples{ | ||
\dontrun{ | ||
getShiftedValues(SGPdata::sgpData_LONG) | ||
} | ||
} | ||
|
||
\keyword{ misc } | ||
\keyword{ models } |