Description Usage Arguments Value Examples
Adjust a dependent variable y linearly to several independent variables x1, x2 ...
1 |
formula |
A formula that gives the relationship of the adjustment. |
data |
A dataframe which contains the dependent and the independent variables. |
A dataframe containing a new column with the adjusted values.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | load.pkgs( c( "ggplot2" ) )
set.seed( 1 )
num <- 100
sexes <- c( "female", "male" )
d <- data.frame( sex = sample( sexes, num, T, prob = c( .3, .7 ) ), age = round( runif( num, 0, 20 ), 1 ) )
d$y <- c( 30, 35 )[ match( d$sex, sexes ) ] + c( 2, 3 )[ match( d$sex, sexes ) ] * d$age + rnorm( num, 0, 10 )
d <- adjust.linearly( y ~ age, d )
d <- adjust.linearly( y ~ sex, d )
d <- adjust.linearly( y ~ age * sex, d )
thm <- list( theme_bw( ), geom_point( ), geom_smooth( method = "lm" ) )
thm.brown <- list( theme_bw( ), geom_point( col = "green3" ), geom_smooth( col = "green3", method = "lm" ) )
thm.bicol <- list.append( thm, scale_color_manual( values = c( "firebrick1", "steelblue3" ), guide = F ) )
thm.bicolfac <- list.append( thm.bicol, facet_grid( sex ~ . ) )
ggsubplot(
ggplot( d, aes( age, y ) ) + thm.brown,
ggplot( d, aes( age, y, col = sex ) ) + thm.bicol,
ggplot( d, aes( age, y.adj.for.age ) ) + thm.brown,
ggplot( d, aes( age, y.adj.for.age, col = sex ) ) + thm.bicol,
ggplot( d, aes( age, y.adj.for.sex ) ) + thm.brown,
ggplot( d, aes( age, y.adj.for.sex, col = sex ) ) + thm.bicol,
ggplot( d, aes( age, y.adj.for.age.sex, col = sex ) ) + thm.bicol,
ggplot( d, aes( age, y.adj.for.age.sex, col = sex ) ) + thm.bicolfac,
cols = 4 )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.