# Copyright (C) 2016-2017 Ren-Huai Huang <huangrenhuai@gmail.com>
#
# This file is part of relvm.
#
# relvm is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# relvm is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with relvm. If not, see <http://www.gnu.org/licenses/>.
#' Prepare the subset of the data in a measure group for CMS star rating
#'
#' Prepare the subset of the data table and weight table in each measure group
#' in CMS Hospital Compare star rating. In addition, the hospital is removed if
#' the hospital didn't report any data in the group.
#'
#' @param object A mstbl object,which contains the measure score table and
#' weight table.
#' @param groups A vector of group names. The default is null and it will
#' automatically use all of the groups in the object.
#' @return A list containing a sublist for each measure group. Each has a
#' stadardized measure score table and a weight table.
#'
#' @export
subgroup <- function(object,groups=NULL) {
alldf <- merge(x=object$mstbl_std,y=object$wtbl,all=TRUE)
# all
mtbl <- create_measure_tbl(alldf)
all_groups <- unique(mtbl$group)
if (is.null(groups)) {
groups <- all_groups
} else if (any(groups %in% all_groups)) {
groups <- groups[groups %in% all_groups]
} else stop("The group name do not match.")
alldata<- sapply(groups, sub1group, df=alldf, simplify = FALSE)
alldata
}
#
sub1group <- function(group,df=alldf) {
# Measure table
mtbl <- create_measure_tbl(df)
# data table
measure_name<- mtbl[(mtbl$group %in% group) & (mtbl$type %in% "score"),"name"]
dat_tbl <- df[, names(df) %in% measure_name]
# weight table
wt_name <- sapply(measure_name, function(x) paste0(x,"_wt"))
wt_tbl <- df[, names(df) %in% wt_name]
# remove the na rows
na_row_idx<- apply(is.na(dat_tbl),1,all)
dat_tbl <- dat_tbl[!(na_row_idx),];
wt_tbl <- wt_tbl[!(na_row_idx),];
ccnid <- df[!(na_row_idx),"ccnid",drop=FALSE]
(out <- list(mstbl_std = dat_tbl, wtbl = wt_tbl,ccnid=ccnid))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.