Skip to content

Commit

Permalink
Adding in getShiftedValues function
Browse files Browse the repository at this point in the history
  • Loading branch information
dbetebenner committed Nov 2, 2021
1 parent 5f954b0 commit c42621c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
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")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(bootstrapSRS_SGP)
export(computeHoMetric2)
export(gammaEffectSize)
export(gammaEffectSizeLong)
export(getShiftedValues)
export(hd_qe)
export(amputeScaleScore)
export(imputeScaleScore)
Expand Down
Binary file added R/.getShiftedValues.R.swp
Binary file not shown.
27 changes: 27 additions & 0 deletions R/getShiftedValues.R
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
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ function(libname, pkgname) {
`.onAttach` <-
function(libname, pkgname) {
if (interactive()) {
packageStartupMessage(magenta$bold('cfaTools',paste(paste0(unlist(strsplit(as.character(packageVersion("cfaTools")), "[.]")), c(".", "-", ".", "")), collapse=""),' (10-22-2021). For help: >help("cfaTools") or visit https://centerforassessment.github.io/cfaTools'))
packageStartupMessage(magenta$bold('cfaTools',paste(paste0(unlist(strsplit(as.character(packageVersion("cfaTools")), "[.]")), c(".", "-", ".", "")), collapse=""),' (11-2-2021). For help: >help("cfaTools") or visit https://centerforassessment.github.io/cfaTools'))
}
}
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ citEntry(entry = "Manual",
title = "{cfaTools}: Center for Assessment Tools for Large Scale Educational Assessment Analysis",
author = personList(as.person("Damian W. Betebenner"), as.person("Adam R. Van Iwaarden"), as.person("Nathan Dadey"), as.person("Joseph Martineau")),
year = "2021",
note = "R package version 0.0-1.992",
note = "R package version 0.0-1.993",
url = "https://centerforassessment.github.io/cfaTools/",

textVersion = paste("Damian W. Betebenner, Adam R. Van Iwaarden, Nathan Dadey and Joseph Martineau (2021).",
"cfaTools: Center for Assessment Tools for Large Scale Educational Assessment Analysis",
"(R package version 0.0-1.992",
"(R package version 0.0-1.993",
"URL https://centerforassessment.github.io/cfaTools/")
)
4 changes: 2 additions & 2 deletions man/cfaTools-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Center for Assessment developed Tools for Large Scale Educational Assessment.
\tabular{ll}{
Package: \tab cfaTools\cr
Type: \tab Package\cr
Version: \tab 0.0-1.992\cr
Date: \tab 2021-10-22\cr
Version: \tab 0.0-1.993\cr
Date: \tab 2021-11-2\cr
License: \tab GPL-3\cr
LazyLoad: \tab yes\cr
}
Expand Down
47 changes: 47 additions & 0 deletions man/getShiftValues.Rd
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 }

0 comments on commit c42621c

Please sign in to comment.