Quick followup to Gary's post -- on converting from the triangular 'recovery matrix' (which aggregates the data over individuals) to a 'standard' encounter-history file, with the added twist of going from aggregate -> individual records (i.e., one line, and on EH, per individual). This is necessary if you want to use an individual covariate.
As Gary pointed out, first step is to export the residuals to an Excel file: 'Output | Specific Model | Output residuals'. In this Excel file, there will be columns for the 'History', 'Observed', and 'Expected'. Its the first two you want. Now, while it is possible to do the next steps in Excel, here is one (out of like many alternatives) approach using R (since more folks use R these days for various things).
1\ copy the 'History' and 'Observed' columns from the Excel spreadsheet to an ASCII file, with at least a space between the history, and the aggregated history. I'll call this file aggregated.inp.
2\ fire up R, and run the following script (modifying file paths and anything else as needed):
- Code: Select all
# step 1) get aggregated encounter data
aggregated <- read.table("C:/users/egc/Desktop/aggregate.inp", header=F);
colnames(aggregated) <- c("history","observed");
# step 2) initialize the file you will output individual histories to...
file.create("c:/users/egc/Desktop/individual.inp", showWarnings = FALSE)
# step 3) the main routine -- replicate each history freq times
for (i in 1:nrow(aggregated)) {
indiv <- replicate(aggregated$observed[i],aggregated$history[i]);
indiv <- as.data.frame(indiv);
# add the following at end of each history
indiv$count <- " 1;";
write.table(indiv, file="c:/users/egc/Desktop/individual.inp", sep=" ", append=TRUE , quote= FALSE, row.names=FALSE, col.names=FALSE)
}
The file 'individual.inp' should contain the reformatted individual encounter histories. You can modify this new file to include individual covariates -- simply strip off the semipcolon after the '1;' at the end of each line, and append the appropriate covariate value to the right of the 1 (separated by a space from the 1). The formatting for individual covariates is covered in chapter 2 and chapter 11.