Generate matrix specifying linear estimate.

LE_matrix(object, effect = NULL, at = NULL)

# S3 method for default
LE_matrix(object, effect = NULL, at = NULL)

aggregate_linest_list(linest_list)

get_linest_list(object, effect = NULL, at = NULL)

Arguments

object

Model object

effect

A vector of variables. For each configuration of these the estimate will be calculated.

at

Either NULL, a list or a dataframe. 1) If a list, then the list must consist of covariates (including levels of some factors) to be used in the calculations. 2) If a dataframe, the dataframe is split rowwise and the function is invoked on each row.

linest_list

Linear estimate list (as generated by get_linest_list).

Details

Check this

See also

Examples


## Two way anova:

data(warpbreaks)

## An additive model
m0 <- lm(breaks ~ wool + tension, data=warpbreaks)

## Estimate mean for each wool type, for tension="M":
K <- LE_matrix(m0, at=list(wool=c("A", "B"), tension="M"))
K
#>      (Intercept) woolB tensionM tensionH
#> [1,]           1     0        1        0
#> [2,]           1     1        1        0

## Vanilla computation:
K %*% coef(m0)
#>          [,1]
#> [1,] 29.27778
#> [2,] 23.50000

## Alternative; also providing standard errors etc:
linest(m0, K)
#>      estimate std.error statistic      df p.value
#> [1,]  29.2778    3.1618    9.2599 50.0000       0
#> [2,]  23.5000    3.1618    7.4325 50.0000       0
esticon(m0, K)
#>        estimate  std.error  statistic    p.value      beta0 df
#> [1,] 2.9278e+01 3.1618e+00 9.2599e+00 2.0017e-12 0.0000e+00 50
#> [2,] 2.3500e+01 3.1618e+00 7.4325e+00 1.2661e-09 0.0000e+00 50

## Estimate mean for each wool type when averaging over tension;
# two ways of doing this
K <- LE_matrix(m0, at=list(wool=c("A", "B")))
K
#>      (Intercept) woolB  tensionM  tensionH
#> [1,]           1     0 0.3333333 0.3333333
#> [2,]           1     1 0.3333333 0.3333333
K <- LE_matrix(m0, effect="wool")
K
#>      (Intercept) woolB  tensionM  tensionH
#> [1,]           1     0 0.3333333 0.3333333
#> [2,]           1     1 0.3333333 0.3333333
linest(m0, K)
#>      estimate std.error statistic      df p.value
#> [1,]  31.0370    2.2357   13.8824 50.0000       0
#> [2,]  25.2593    2.2357   11.2981 50.0000       0

## The linear estimate is sometimes called to "least squares mean"
# (LSmeans) or popupulation means.
# Same as
LSmeans(m0, effect="wool")
#>      estimate std.error statistic      df p.value
#> [1,]  31.0370    2.2357   13.8824 50.0000       0
#> [2,]  25.2593    2.2357   11.2981 50.0000       0

## Without mentioning 'effect' or 'at' an average across all
#predictors are calculated:
K <- LE_matrix(m0)
K
#>      (Intercept) woolB  tensionM  tensionH
#> [1,]           1   0.5 0.3333333 0.3333333
linest(m0, K)
#>      estimate std.error statistic      df p.value
#> [1,]  28.1481    1.5809   17.8052 50.0000       0

## Because the design is balanced (9 observations per combination
#of wool and tension) this is the same as computing the average. If
#the design is not balanced, the two quantities are in general not
#the same.
mean(warpbreaks$breaks)
#> [1] 28.14815

## Same as 
LSmeans(m0)
#>      estimate std.error statistic      df p.value
#> [1,]  28.1481    1.5809   17.8052 50.0000       0

## An interaction model 
m1 <- lm(breaks ~ wool * tension, data=warpbreaks)

K <- LE_matrix(m1, at=list(wool=c("A", "B"), tension="M"))
K
#>      (Intercept) woolB tensionM tensionH woolB:tensionM woolB:tensionH
#> [1,]           1     0        1        0              0              0
#> [2,]           1     1        1        0              1              0
linest(m1, K)
#>      estimate std.error statistic      df p.value
#> [1,]  24.0000    3.6468    6.5812 48.0000       0
#> [2,]  28.7778    3.6468    7.8913 48.0000       0
K <- LE_matrix(m1, at=list(wool=c("A", "B")))
K
#>      (Intercept) woolB  tensionM  tensionH woolB:tensionM woolB:tensionH
#> [1,]           1     0 0.3333333 0.3333333      0.0000000      0.0000000
#> [2,]           1     1 0.3333333 0.3333333      0.3333333      0.3333333
linest(m1, K)
#>      estimate std.error statistic      df p.value
#> [1,]  31.0370    2.1055   14.7412 48.0000       0
#> [2,]  25.2593    2.1055   11.9970 48.0000       0
K <- LE_matrix(m1, effect="wool")
K
#>      (Intercept) woolB  tensionM  tensionH woolB:tensionM woolB:tensionH
#> [1,]           1     0 0.3333333 0.3333333      0.0000000      0.0000000
#> [2,]           1     1 0.3333333 0.3333333      0.3333333      0.3333333
linest(m1, K)
#>      estimate std.error statistic      df p.value
#> [1,]  31.0370    2.1055   14.7412 48.0000       0
#> [2,]  25.2593    2.1055   11.9970 48.0000       0
LSmeans(m1, effect="wool")
#>      estimate std.error statistic      df p.value
#> [1,]  31.0370    2.1055   14.7412 48.0000       0
#> [2,]  25.2593    2.1055   11.9970 48.0000       0

K <- LE_matrix(m1)
K
#>      (Intercept) woolB  tensionM  tensionH woolB:tensionM woolB:tensionH
#> [1,]           1   0.5 0.3333333 0.3333333      0.1666667      0.1666667
linest(m1, K)
#>      estimate std.error statistic      df p.value
#> [1,]  28.1481    1.4888   18.9068 48.0000       0
LSmeans(m1)
#>      estimate std.error statistic      df p.value
#> [1,]  28.1481    1.4888   18.9068 48.0000       0