Learn R Programming

hopit (version 0.9.0)

getLevels: Summarize the adjusted and the original self-rated response levels

Description

Summarize the adjusted and the original self-rated response levels.

Usage

getLevels(model, formula = model$thresh.formula,
  data = environment(model$thresh.formula), decreasing.levels = TRUE,
  sort.flag = FALSE, plotf = TRUE, sep = "_", mar = c(7, 2, 1.5,
  0.5), oma = c(0, 3, 0, 0), YLab = "Fraction [%]", YLab.cex = 1.1,
  legbg = grDevices::adjustcolor("white", alpha.f = 0.4), legbty = "o")

Arguments

model

a fitted hopit model.

formula

a formula containing the grouping variables. It is by default set to threshold formula.

data

data used to fit the model.

decreasing.levels

a logical indicating whether self-reported health classes are ordered in increasing order.

sort.flag

a logical indicating whether to sort the levels.

plotf

a logical indicating whether to plot the results.

sep

a separator for the level names.

mar, oma

graphic parameters, see par.

YLab, YLab.cex

a label for the y-axis and it's size.

legbg

a legend background color. See bg parameter in legend.

legbty

a legend box type. See bty parameter in legend.

Value

a list with the following components:

original

frequencies of original response levels for selected groups/categories.

adjusted

frequencies of adjusted response levels (Jurges 2007 method) for selected groups/categories.

N.original

the number of original response levels for selected groups/categories.

N.adjusted

the number of adjusted response levels (Jurges 2007 method) for selected groups/categories.

categories

selected groups/categories used in summary.

tab

an original vs. an adjusted contingency table.

mat

a matrix with columns: grouping variables, original response levels, adjusted response levels. Each row corresponds to a single individual from the data used to fit the model.

References

Jurges2007hopit OKSUZYAN2019hopit

See Also

getCutPoints, latentIndex, standardiseCoef, hopit.

Examples

Run this code
# NOT RUN {
# DATA
data(healthsurvey)

# the order of response levels decreases from the best health to
# the worst health; hence the hopit() parameter decreasing.levels
# is set to TRUE
levels(healthsurvey$health)

# fit a model
model1 <- hopit(latent.formula = health ~ hypertension + high_cholesterol +
                heart_attack_or_stroke + poor_mobility + very_poor_grip +
                depression + respiratory_problems +
                IADL_problems + obese + diabetes + other_diseases,
              thresh.formula = ~ sex + ageclass + country,
              decreasing.levels = TRUE,
              control = list(trace = FALSE),
              data = healthsurvey)

# Example 1 ---------------------

# calculate a summary by country
hl <- getLevels(model=model1, formula=~ country,
                data = healthsurvey,
                sep=' ', plotf=TRUE)

# differences between frequencies of original and adjusted health levels
round(100*(hl$original - hl$adjusted),2)

# extract good and bad health levels (combined levels)
Org <- cbind(bad = rowSums(hl$original[,1:2]),
             good = rowSums(hl$original[,4:5]))
Adj <- cbind(bad = rowSums(hl$adjusted[,1:2]),
             good = rowSums(hl$adjusted[,4:5]))
round(100*(Org - Adj),2)

# plot the differences
barplot(t(Org - Adj), beside = TRUE, density = 20, angle = c(-45, 45),
        col = c('pink4', 'green2'),
        ylab = 'Original - adjusted reported health frequencies')
abline(h = 0); box()
legend('top', c('Bad health','Good health'),
       density = 20, angle = c(-45, 45),
       fill = c('pink4', 'green2'), bty = 'n', cex = 1.2)

# in country X, bad health seems to be over-reported while good health
# is under-reported; in country Z, good health is highly over-reported.

# Example 2 ---------------------

# summary by gender and age
hl <- getLevels(model = model1, formula=~ sex + ageclass,
                data = healthsurvey,
                sep=' ', plotf=TRUE)

# differences between frequencies of original and adjusted health levels
round(100*(hl$original - hl$adjusted),2)

# extract good health levels (combined "Very good" and "Excellent" levels)
Org <- rowSums(hl$original[,4:5])
Adj <- rowSums(hl$adjusted[,4:5])
round(100*(Org - Adj),2)

pmar <- par('mar'); par(mar = c(9.5, pmar[2:4]))
barplot(Org-Adj,
        ylab = 'Original - adjusted reported good health frequencies',
        las = 3,
        density = 20, angle = c(45, -45), col = c('blue', 'orange'))
abline(h = 0); box(); par(mar = pmar)
legend('top', c('Man','Woman'), density = 20, angle = c(-45, 45),
       fill = c('blue', 'orange'), bty = 'n', cex = 1.2)

# results show that women in general tend to over-report good health,
# while men aged 50-59 greatly under-report good health.

# more examples can be found in the description of the boot_hopit() function.
# }

Run the code above in your browser using DataLab