Learn R Programming

mbgraphic (version 1.0.1)

groups: Quantifying the influence of a factor variable

Description

The function calculates a linear model by calling lm(xi~classvar) for all numeric variables (xi) from x and returns the coefficients of determination. The aim is to find numeric variables for which high ratios of the variability can be explained by a factor variable classvar.

Usage

groups(data, classvar)

Arguments

data

A data frame.

classvar

A factor. The variable which is used to explain the numeric variables from x.

Value

If x is a numeric vector, the coefficient of determination of the model described by lm(x~classvar) is returned. Otherwise a data frame with the following two variables:

groups

coefficient of determination.

variable

actual variable.

See Also

groups_maxplot, lm

Examples

Run this code
# NOT RUN {
data(Election2005)
# }
# NOT RUN {
# Define new variable which explains affiliation of the constituencies
# to east Germany, west Germany and Berlin 
OstWest <-  ifelse(Election2005$Land %in% 
    c("Thueringen","Sachsen","Sachsen-Anhalt",
    "Brandenburg","Mecklenburg-Vorpommern"),  "Ost", "West")
Election2005$OstWestBerlin <- 
  as.factor(ifelse(Election2005$Land == "Berlin","Berlin",OstWest))

# Calculate measure groups 
groupm <- groups(Election2005, "OstWestBerlin")
# Show highest values 
groupm[with(groupm,order(groups,decreasing=TRUE))[1:10],]
# }

Run the code above in your browser using DataLab