make.communal: Put communals in "fixed" data frame

View source: R/make.communal.R

make.communalR Documentation

Put communals in "fixed" data frame

Description

Given an ordinary data frame suitable for survival analysis, and a data frame with "communal" time series, this function includes the communal covariates as fixed, by the "cutting spells" method.

Usage

make.communal(
  dat,
  com.dat,
  communal = TRUE,
  start,
  period = 1,
  lag = 0,
  surv = c("enter", "exit", "event", "birthdate"),
  tol = 1e-04,
  fortran = TRUE
)

Arguments

dat

A data frame containing interval specified survival data and covariates, of which one must give a "birth date", the connection between duration and calendar time

com.dat

Data frame with communal covariates. They must have the same start year and periodicity, given by start and lag.

communal

Boolean; if TRUE, then it is a true communal (default), otherwise a fixed. The first component is the first year (start date in decimal form), and the second component is the period length. The third is lag and the fourth is scale.

start

Start date in decimal form.

period

Period length. Defaults to one.

lag

The lag of the effect. Defaults to zero.

surv

Character vector of length 4 giving the names of interval start, interval end, event indicator, birth date, in that order. These names must correspond to names in dat

tol

Largest length of an interval considered to be of zero length. The cutting sometimes produces zero length intervals, which we want to discard.

fortran

If TRUE, then a Fortran implementation of the function is used. This is the default. This possibility is only for debugging purposes. You should of course get identical results with the two methods.

Details

The main purpose of this function is to prepare a data file for use with coxreg, aftreg, and coxph.

Value

The return value is a data frame with the same variables as in the combination of dat and com.dat. Therefore it is an error to have common name(s) in the two data frames.

Note

Not very vigorously tested.

Author(s)

Göran Broström

See Also

coxreg, aftreg, coxph, cal.window

Examples


dat <- data.frame(enter = 0, exit = 5.731, event = 1,
birthdate = 1962.505, x = 2)
## Birth date: July 2, 1962 (approximately).
com.dat <- data.frame(price = c(12, 3, -5, 6, -8, -9, 1, 7))
dat.com <- make.communal(dat, com.dat, start = 1962.000) 


goranbrostrom/eha documentation built on June 19, 2024, 1:39 a.m.