File: match.data.R

package info (click to toggle)
matchit 2.4-13-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,040 kB
  • ctags: 51
  • sloc: makefile: 24; csh: 13
file content (36 lines) | stat: -rw-r--r-- 1,210 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
match.data <- function(object, group = "all", distance = "distance",
                       weights = "weights", subclass = "subclass") {
  data <- eval(object$call$data)
  treat <- object$treat
  wt <- object$weights
  vars <- names(data)
  if (distance %in% vars)
    stop("invalid input for distance. choose a different name.")
  else if (!is.null(object$distance)) {
    dta <- data.frame(cbind(data, object$distance))
    names(dta) <- c(names(data), distance)
    data <- dta
  }
  if (weights %in% vars)
    stop("invalid input for weights. choose a different name.")
  else if (!is.null(object$weights)){
    dta <- data.frame(cbind(data, object$weights))
    names(dta) <- c(names(data), weights)
    data <- dta
  }
  if (subclass %in% vars)
    stop("invalid input for subclass. choose a different name.")
  else if (!is.null(object$subclass)){
    dta <- data.frame(cbind(data, object$subclass))
    names(dta) <- c(names(data), subclass)
    data <- dta
  }
  if (group == "all")
    return(data[wt > 0,])
  else if (group == "treat")
    return(data[wt > 0 & treat == 1,])
  else if (group == "control")
    return(data[wt > 0 & treat == 0,])
  else
    stop("error: invalid input for group.")
}