diff --git a/docs/extractingBaseCodes.md b/docs/extractingBaseCodes.md index 59f40dd..3b463b6 100644 --- a/docs/extractingBaseCodes.md +++ b/docs/extractingBaseCodes.md @@ -1,146 +1,161 @@ -## Extracting Hypotheses from R Base Contrast Codes +## Extracting Hypotheses from Base R Contrast Codes -**CALM** can take existing coding patterns and decode them to determine the hypotheses being tested. The examples below use the built-in codes in R (treatment, SAS, sum, helmert, and poly) and extract the hypotheses implied by each code vector. +**CALM** can take existing coding patterns and decode them to determine +the hypotheses being tested. The examples below use the built-in codes +in R (treatment, SAS, sum, helmert, and poly) and extract the hypotheses +implied by each code vector. -The package takes matrix input of the coding pattern (columns represent coded vectors, rows represent the groups being represented) and outputs the linear contrasts hypotheses being represented (the rows represent the weights for the contrast, the columns represent the groups being compared). +The package takes matrix input of the coding pattern (columns represent +coded vectors, rows represent the groups being represented) and outputs +the linear contrasts hypotheses being represented (the rows represent +the weights for the contrast, the columns represent the groups being +compared). + +- [contr.treatment](#contr.treatment) +- [contr.SAS](#contr.sas) +- [contr.sum](#contr.sum) +- [contr.helmert](#contr.helmert) +- [contr.poly](#contr.poly) + +------------------------------------------------------------------------ ### contr.treatment +Specify that we wish to examine the existing `contr.treatment` and then +use CALM to decode it into hypotheses. -```r +``` r ex_contr.treatment <- cbind(Int=1,contr.treatment(3)) ex_contr.treatment ``` -``` -## Int 2 3 -## 1 1 0 0 -## 2 1 1 0 -## 3 1 0 1 -``` + ## Int 2 3 + ## 1 1 0 0 + ## 2 1 1 0 + ## 3 1 0 1 -```r +``` r calm.decode(ex_contr.treatment) ``` -``` -## 1 2 3 -## Int 1 0 0 -## 2 -1 1 0 -## 3 -1 0 1 -``` + ## 1 2 3 + ## Int 1 0 0 + ## 2 -1 1 0 + ## 3 -1 0 1 -The intercept is equivalent to the mean of the first group. Parameter represent the difference between each group and the first group. +This shows that the intercept is equivalent to the mean of the first +group. The additional parameters represent the difference between each +group and the first group. ### contr.SAS +Specify that we wish to examine the existing `contr.SAS` and then use +CALM to decode it into hypotheses. -```r +``` r ex_contr.SAS <- cbind(Int=1,contr.SAS(3)) ex_contr.SAS ``` -``` -## Int 1 2 -## 1 1 1 0 -## 2 1 0 1 -## 3 1 0 0 -``` + ## Int 1 2 + ## 1 1 1 0 + ## 2 1 0 1 + ## 3 1 0 0 -```r +``` r calm.decode(ex_contr.SAS) ``` -``` -## 1 2 3 -## Int 0 0 1 -## 1 1 0 -1 -## 2 0 1 -1 -``` + ## 1 2 3 + ## Int 0 0 1 + ## 1 1 0 -1 + ## 2 0 1 -1 -The intercept is equivalent to the mean of the last group. Parameter represent the difference between each group and the last group. +This shows that the intercept is equivalent to the mean of the last +group. The additional parameters represent the difference between each +group and the last group. ### contr.sum +Specify that we wish to examine the existing `contr.sum` and then use +CALM to decode it into hypotheses. -```r +``` r ex_contr.sum <- cbind(Int=1,contr.sum(3)) ex_contr.sum ``` -``` -## Int -## 1 1 1 0 -## 2 1 0 1 -## 3 1 -1 -1 -``` + ## Int + ## 1 1 1 0 + ## 2 1 0 1 + ## 3 1 -1 -1 -```r +``` r calm.decode(ex_contr.sum) ``` -``` -## 1 2 3 -## Int 0.3333 0.3333 0.3333 -## 0.6667 -0.3333 -0.3333 -## -0.3333 0.6667 -0.3333 -``` + ## 1 2 3 + ## Int 0.3333 0.3333 0.3333 + ## 0.6667 -0.3333 -0.3333 + ## -0.3333 0.6667 -0.3333 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +This shows that the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the grand mean. The last group is not compared. ### contr.helmert +Specify that we wish to examine the existing `contr.herlmert` and then +use CALM to decode it into hypotheses. -```r +``` r ex_contr.helmert <- cbind(Int=1,contr.helmert(3)) ex_contr.helmert ``` -``` -## Int -## 1 1 -1 -1 -## 2 1 1 -1 -## 3 1 0 2 -``` + ## Int + ## 1 1 -1 -1 + ## 2 1 1 -1 + ## 3 1 0 2 -```r +``` r calm.decode(ex_contr.helmert) ``` -``` -## 1 2 3 -## Int 0.3333 0.3333 0.3333 -## -0.5000 0.5000 0.0000 -## -0.1667 -0.1667 0.3333 -``` + ## 1 2 3 + ## Int 0.3333 0.3333 0.3333 + ## -0.5000 0.5000 0.0000 + ## -0.1667 -0.1667 0.3333 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +This shows that the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the mean of the subsequent groups. ### contr.poly +Specify that we wish to examine the existing `contr.poly` and then use +CALM to decode it into hypotheses. -```r +``` r ex_contr.poly <- cbind(Int=1,contr.poly(3)) ex_contr.poly ``` -``` -## Int .L .Q -## [1,] 1 -7.071068e-01 0.4082483 -## [2,] 1 -7.850462e-17 -0.8164966 -## [3,] 1 7.071068e-01 0.4082483 -``` + ## Int .L .Q + ## [1,] 1 -7.071068e-01 0.4082483 + ## [2,] 1 -7.850462e-17 -0.8164966 + ## [3,] 1 7.071068e-01 0.4082483 -```r +``` r calm.decode(ex_contr.poly) ``` -``` -## GROUP 1 GROUP 2 GROUP 3 -## Int 0.3333 0.3333 0.3333 -## .L -0.7071 0.0000 0.7071 -## .Q 0.4082 -0.8165 0.4082 -``` + ## GROUP 1 GROUP 2 GROUP 3 + ## Int 0.3333 0.3333 0.3333 + ## .L -0.7071 0.0000 0.7071 + ## .Q 0.4082 -0.8165 0.4082 -The intercept is equivalent to the mean of the group means. Parameters represent polynomial trends (linear, quadratic, etc.). +THis shows that the intercept is equivalent to the mean of the group +means. The additional parameters represent polynomial trends (linear, +quadratic, etc.). diff --git a/docs/extractingRegressionCodes.md b/docs/extractingRegressionCodes.md index a1b272a..b8153a0 100644 --- a/docs/extractingRegressionCodes.md +++ b/docs/extractingRegressionCodes.md @@ -1,13 +1,29 @@ ## Extracting Hypotheses from Regression Codes -**CALM** can take existing coding patterns and decode them to determine the hypotheses being tested. The examples below use traditional and commonly-taught regression codes (dummy codes, effect codes, etc.) and extract the hypotheses implied by each code vector. +**CALM** can take existing coding patterns and decode them to determine +the hypotheses being tested. The examples below use traditional and +commonly-taught regression codes (dummy codes, effect codes, etc.) and +extract the hypotheses implied by each code vector. -The package takes matrix input of the coding pattern (columns represent coded vectors, rows represent the groups being represented) and outputs the linear contrasts hypotheses being represented (the rows represent the weights for the contrast, the columns represent the groups being compared). +The package takes matrix input of the coding pattern (columns represent +coded vectors, rows represent the groups being represented) and outputs +the linear contrasts hypotheses being represented (the rows represent +the weights for the contrast, the columns represent the groups being +compared). + +- [Dummy Coding](#dummy-coding) +- [Effect Coding](#effect-coding) +- [Repeated Coding](#repeated-coding) + +------------------------------------------------------------------------ ### Dummy Coding -```r +Specify a matrix of dummy codes and then use CALM to decode it into +hypotheses. + +``` r ex_dummy <- matrix(c( 1,1,0, 1,0,1, @@ -17,18 +33,21 @@ ex_dummy <- matrix(c( calm.decode(ex_dummy) ``` -``` -## GROUP 1 GROUP 2 GROUP 3 -## HYPOTH 1 0 0 1 -## HYPOTH 2 1 0 -1 -## HYPOTH 3 0 1 -1 -``` + ## GROUP 1 GROUP 2 GROUP 3 + ## HYPOTH 1 0 0 1 + ## HYPOTH 2 1 0 -1 + ## HYPOTH 3 0 1 -1 -The intercept is equivalent to the mean of the last group. Parameters represent the difference between each group and the last group. +This shows that the intercept is equivalent to the mean of the last +group. THe additional parameters represent the difference between each +group and the last group. ### Effect Coding -```r +Specify a matrix of effect codes and then use CALM to decode it into +hypotheses. + +``` r ex_effect <- matrix(c( 1,1,0, 1,0,1, @@ -38,18 +57,21 @@ ex_effect <- matrix(c( calm.decode(ex_effect) ``` -``` -## GROUP 1 GROUP 2 GROUP 3 -## HYPOTH 1 0.3333 0.3333 0.3333 -## HYPOTH 2 0.6667 -0.3333 -0.3333 -## HYPOTH 3 -0.3333 0.6667 -0.3333 -``` + ## GROUP 1 GROUP 2 GROUP 3 + ## HYPOTH 1 0.3333 0.3333 0.3333 + ## HYPOTH 2 0.6667 -0.3333 -0.3333 + ## HYPOTH 3 -0.3333 0.6667 -0.3333 -The intercept is equivalent to the mean of the group means. Parameter represent the difference between each group and the grand mean. The last group is not compared. +This shows that the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the grand mean. The last group is not compared. ### Repeated Coding -```r +Specify a matrix of repeated codes and then use CALM to decode it into +hypotheses. + +``` r ex_repeated <- matrix(c( 1,0,0, 1,1,0, @@ -59,11 +81,11 @@ ex_repeated <- matrix(c( calm.decode(ex_repeated) ``` -``` -## GROUP 1 GROUP 2 GROUP 3 -## HYPOTH 1 1 0 0 -## HYPOTH 2 -1 1 0 -## HYPOTH 3 0 -1 1 -``` + ## GROUP 1 GROUP 2 GROUP 3 + ## HYPOTH 1 1 0 0 + ## HYPOTH 2 -1 1 0 + ## HYPOTH 3 0 -1 1 -The intercept is equivalent to the mean of the first group. Parameter represent the difference between each group and the previous group. +This shows that the intercept is equivalent to the mean of the first +group. The additional parameters represent the difference between each +group and the previous group. diff --git a/docs/producingCommonCodes.md b/docs/producingCommonCodes.md index 3448e4b..a533588 100644 --- a/docs/producingCommonCodes.md +++ b/docs/producingCommonCodes.md @@ -1,16 +1,38 @@ ## Producing Common Contrast Codes -**CALM** can take a set of linear contrasts to be tested and encode them into coding schemes. The examples below take some common contrasts (treatment, control, deviation, etc.) and produce the coding scheme associated with it. - -The package takes linear contrast weights (rows represented the weights for the groups, columns represent the different groups) and provides the coding pattern (where columns represent vector codes, rows represent the groups). +**CALM** can take a set of linear contrasts to be tested and encode them +into coding schemes. The examples below take some common contrasts +(treatment, control, deviation, etc.) and produce the coding scheme +associated with it. + +The package takes linear contrast weights (rows represented the weights +for the groups, columns represent the different groups) and provides the +coding pattern (where columns represent vector codes, rows represent the +groups). + +- [Treatment (First) Contrasts](#treatment-(first)-contrasts) +- [Treatment (Last) Contrasts](#treatment-(last)-contrasts) +- [Control (First) Contrasts](#control-(first)-contrasts) +- [Control (Last) Contrasts](#control-(last)-contrasts) +- [Deviation (First) Contrasts](#deviation-(first)-contrasts) +- [Deviation (Last) Contrasts](#deviation-(last)-contrasts) +- [Helmert (Forward) Contrasts](#helmert-(forward)-contrasts) +- [Helmert (Reverse) Contrasts](#helmert-(reverse)-contrasts) +- [Repeated (Forward) Contrasts](#repeated-(forward)-contrasts) +- [Repeated (Reverse) Contrasts](#repeated-(reverse)-contrasts) +- [Difference (Forward) Contrasts](#difference-(forward)-contrasts) +- [Difference (Reverse) Contrasts](#difference-(reverse)-contrasts) + +------------------------------------------------------------------------ ### Treatment (First) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the first group. - +For this set of hypotheses, the intercept is equivalent to mean of the +first group. The additional parameters represent the difference between +each group and the first group. -```r +``` r M1 <- c(1,0,0) H1 <- c(-1,1,0) H2 <- c(-1,0,1) @@ -18,19 +40,18 @@ ex_treatment.first <- rbind(M1,H1,H2) calm.encode(ex_treatment.first) ``` -``` -## M1 H1 H2 -## GROUP 1 1 0 0 -## GROUP 2 1 1 0 -## GROUP 3 1 0 1 -``` + ## M1 H1 H2 + ## GROUP 1 1 0 0 + ## GROUP 2 1 1 0 + ## GROUP 3 1 0 1 ### Treatment (Last) Contrasts -The intercept is equivalent to mean of the last group. Parameters represent the difference between each group and the last group. - +For this set of hypotheses, the intercept is equivalent to mean of the +last group. The additional parameters represent the difference between +each group and the last group. -```r +``` r M3 <- c(0,0,1) H1 <- c(1,0,-1) H2 <- c(0,1,-1) @@ -38,19 +59,18 @@ ex_treatment.last <- rbind(M3,H1,H2) calm.encode(ex_treatment.last) ``` -``` -## M3 H1 H2 -## GROUP 1 1 1 0 -## GROUP 2 1 0 1 -## GROUP 3 1 0 0 -``` + ## M3 H1 H2 + ## GROUP 1 1 1 0 + ## GROUP 2 1 0 1 + ## GROUP 3 1 0 0 ### Control (First) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the first group. - +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the first group. -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(-1,1,0) H2 <- c(-1,0,1) @@ -58,19 +78,18 @@ ex_control.first <- rbind(GM,H1,H2) calm.encode(ex_control.first) ``` -``` -## GM H1 H2 -## GROUP 1 1 -0.3333 -0.3333 -## GROUP 2 1 0.6667 -0.3333 -## GROUP 3 1 -0.3333 0.6667 -``` + ## GM H1 H2 + ## GROUP 1 1 -0.3333 -0.3333 + ## GROUP 2 1 0.6667 -0.3333 + ## GROUP 3 1 -0.3333 0.6667 ### Control (Last) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the last group. +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the last group. - -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(1,0,-1) H2 <- c(0,1,-1) @@ -78,19 +97,18 @@ ex_control.last <- rbind(GM,H1,H2) calm.encode(ex_control.last) ``` -``` -## GM H1 H2 -## GROUP 1 1 0.6667 -0.3333 -## GROUP 2 1 -0.3333 0.6667 -## GROUP 3 1 -0.3333 -0.3333 -``` + ## GM H1 H2 + ## GROUP 1 1 0.6667 -0.3333 + ## GROUP 2 1 -0.3333 0.6667 + ## GROUP 3 1 -0.3333 -0.3333 ### Deviation (First) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the grand mean. The first group is not compared. +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the grand mean. The first group is not compared. - -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(-1/3,2/3,-1/3) H2 <- c(-1/3,-1/3,2/3) @@ -98,19 +116,18 @@ ex_deviation.first <- rbind(GM,H1,H2) calm.encode(ex_deviation.first) ``` -``` -## GM H1 H2 -## GROUP 1 1 -1 -1 -## GROUP 2 1 1 0 -## GROUP 3 1 0 1 -``` + ## GM H1 H2 + ## GROUP 1 1 -1 -1 + ## GROUP 2 1 1 0 + ## GROUP 3 1 0 1 ### Deviation (Last) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. - +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the grand mean. The last group is not compared. -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(2/3,-1/3,-1/3) H2 <- c(-1/3,2/3,-1/3) @@ -118,19 +135,18 @@ ex_deviation.last <- rbind(GM,H1,H2) calm.encode(ex_deviation.last) ``` -``` -## GM H1 H2 -## GROUP 1 1 1 0 -## GROUP 2 1 0 1 -## GROUP 3 1 -1 -1 -``` + ## GM H1 H2 + ## GROUP 1 1 1 0 + ## GROUP 2 1 0 1 + ## GROUP 3 1 -1 -1 ### Helmert (Forward) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the mean of the subsequent groups. - -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(1,-1/2,-1/2) H2 <- c(0,1,-1) @@ -138,19 +154,18 @@ ex_helmert.forward <- rbind(GM,H1,H2) calm.encode(ex_helmert.forward) ``` -``` -## GM H1 H2 -## GROUP 1 1 0.6667 0.0 -## GROUP 2 1 -0.3333 0.5 -## GROUP 3 1 -0.3333 -0.5 -``` + ## GM H1 H2 + ## GROUP 1 1 0.6667 0.0 + ## GROUP 2 1 -0.3333 0.5 + ## GROUP 3 1 -0.3333 -0.5 ### Helmert (Reverse) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the mean of the previous groups. +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the mean of the previous groups. - -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(-1,1,0) H2 <- c(-1/2,-1/2,1) @@ -158,19 +173,18 @@ ex_helmert.reverse <- rbind(GM,H1,H2) calm.encode(ex_helmert.reverse) ``` -``` -## GM H1 H2 -## GROUP 1 1 -0.5 -0.3333 -## GROUP 2 1 0.5 -0.3333 -## GROUP 3 1 0.0 0.6667 -``` + ## GM H1 H2 + ## GROUP 1 1 -0.5 -0.3333 + ## GROUP 2 1 0.5 -0.3333 + ## GROUP 3 1 0.0 0.6667 ### Repeated (Forward) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the subsequent group. - +For this set of hypotheses, the intercept is equivalent to mean of the +first group. The additional parameters represent the difference between +each group and the subsequent group. -```r +``` r M1 <- c(1,0,0) H1 <- c(1,-1,0) H2 <- c(0,1,-1) @@ -178,19 +192,18 @@ ex_repeated.forward <- rbind(M1,H1,H2) calm.encode(ex_repeated.forward) ``` -``` -## M1 H1 H2 -## GROUP 1 1 0 0 -## GROUP 2 1 -1 0 -## GROUP 3 1 -1 -1 -``` + ## M1 H1 H2 + ## GROUP 1 1 0 0 + ## GROUP 2 1 -1 0 + ## GROUP 3 1 -1 -1 ### Repeated (Reverse) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the previous group. +For this set of hypotheses, the intercept is equivalent to mean of the +first group. The additional parameters represent the difference between +each group and the previous group. - -```r +``` r M1 <- c(1,0,0) H1 <- c(-1,1,0) H2 <- c(0,-1,1) @@ -198,19 +211,18 @@ ex_repeated.reverse <- rbind(M1,H1,H2) calm.encode(ex_repeated.reverse) ``` -``` -## M1 H1 H2 -## GROUP 1 1 0 0 -## GROUP 2 1 1 0 -## GROUP 3 1 1 1 -``` + ## M1 H1 H2 + ## GROUP 1 1 0 0 + ## GROUP 2 1 1 0 + ## GROUP 3 1 1 1 ### Difference (Forward) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the subsequent group. +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the subsequent group. - -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(1,-1,0) H2 <- c(0,1,-1) @@ -218,19 +230,18 @@ ex_difference.forward <- rbind(GM,H1,H2) calm.encode(ex_difference.forward) ``` -``` -## GM H1 H2 -## GROUP 1 1 0.6667 0.3333 -## GROUP 2 1 -0.3333 0.3333 -## GROUP 3 1 -0.3333 -0.6667 -``` + ## GM H1 H2 + ## GROUP 1 1 0.6667 0.3333 + ## GROUP 2 1 -0.3333 0.3333 + ## GROUP 3 1 -0.3333 -0.6667 ### Difference (Reverse) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the previous group. - +For this set of hypotheses, the intercept is equivalent to mean of the +group means. The additional parameters represent the difference between +each group and the previous group. -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(-1,1,0) H2 <- c(0,-1,1) @@ -238,9 +249,7 @@ ex_difference.reverse <- rbind(GM,H1,H2) calm.encode(ex_difference.reverse) ``` -``` -## GM H1 H2 -## GROUP 1 1 -0.6667 -0.3333 -## GROUP 2 1 0.3333 -0.3333 -## GROUP 3 1 0.3333 0.6667 -``` + ## GM H1 H2 + ## GROUP 1 1 -0.6667 -0.3333 + ## GROUP 2 1 0.3333 -0.3333 + ## GROUP 3 1 0.3333 0.6667 diff --git a/docs/producingCustomCodes.md b/docs/producingCustomCodes.md index 53fc918..e4e65a6 100644 --- a/docs/producingCustomCodes.md +++ b/docs/producingCustomCodes.md @@ -1,16 +1,29 @@ ## Producing Custom Contrast Codes -**CALM** can take a set of linear contrasts to be tested and encode them into coding schemes. The examples below take custom contrasts (both orthogonal and nonorthogonal) and produce the coding scheme associated with it. +**CALM** can take a set of linear contrasts to be tested and encode them +into coding schemes. The examples below take custom contrasts (both +orthogonal and nonorthogonal) and produce the coding scheme associated +with it. -The package takes linear contrast weights (rows represented the weights for the groups, columns represent the different groups) and provides the coding pattern (where columns represent vector codes, rows represent the groups). +The package takes linear contrast weights (rows represented the weights +for the groups, columns represent the different groups) and provides the +coding pattern (where columns represent vector codes, rows represent the +groups). -### Orthogonal Contrasts +- [Orthogonal Contrasts](#orthogonal-contrasts) +- [Nonorthogonal Contrasts](#nonorthogonal-contrasts) + +------------------------------------------------------------------------ -In this custom example, the intercept is equivalent to mean of the group means. The first parameter represents the difference between the first group and mean of the subsequent groups. The second parameter represents the difference between the second and third groups. +### Orthogonal Contrasts +In this custom example, the intercept is equivalent to mean of the group +means. The first parameter represents the difference between the first +group and mean of the subsequent groups. The second parameter represents +the difference between the second and third groups. -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(1,-1/2,-1/2) H2 <- c(0,1,-1) @@ -18,19 +31,19 @@ ex_custom.orthogonal <- rbind(GM,H1,H2) calm.encode(ex_custom.orthogonal) ``` -``` -## GM H1 H2 -## GROUP 1 1 0.6667 0.0 -## GROUP 2 1 -0.3333 0.5 -## GROUP 3 1 -0.3333 -0.5 -``` + ## GM H1 H2 + ## GROUP 1 1 0.6667 0.0 + ## GROUP 2 1 -0.3333 0.5 + ## GROUP 3 1 -0.3333 -0.5 ### Nonorthogonal Contrasts -In this custom example, the intercept is equivalent to mean of the first group. The first parameter represents the difference between the first group and mean of the subsequent groups. The second parameter represents the difference between the first and second groups. - +In this custom example, the intercept is equivalent to mean of the first +group. The first parameter represents the difference between the first +group and mean of the subsequent groups. The second parameter represents +the difference between the first and second groups. -```r +``` r GM <- c(1,0,0) H1 <- c(1,-1/2,-1/2) H2 <- c(1,-1,0) @@ -38,9 +51,7 @@ ex_custom.nonorthogonal <- rbind(GM,H1,H2) calm.encode(ex_custom.nonorthogonal) ``` -``` -## GM H1 H2 -## GROUP 1 1 0 0 -## GROUP 2 1 0 -1 -## GROUP 3 1 -2 1 -``` + ## GM H1 H2 + ## GROUP 1 1 0 0 + ## GROUP 2 1 0 -1 + ## GROUP 3 1 -2 1 diff --git a/docs/usingCommonCodes.md b/docs/usingCommonCodes.md index 342de68..63ba0ec 100644 --- a/docs/usingCommonCodes.md +++ b/docs/usingCommonCodes.md @@ -1,263 +1,290 @@ -## Using Common Contrast Codes in Linear Models - -**CALM** includes a complete set of commonly used coding schemes that can be used directly in linear model specifications. The examples below use the built-in codes in the context of a General Linear Model to test the associated hypotheses. +## Using Common Contrast Codes + +**CALM** includes a complete set of commonly used coding schemes that +can be used directly in linear model specifications. The examples below +use the built-in codes in the context of a General Linear Model to test +the associated hypotheses. + +- [The Data](#the-data) +- [Treatment (First) Contrasts](#treatment-(first)-contrasts) +- [Treatment (Last) Contrasts](#treatment-(last)-contrasts) +- [Control (First) Contrasts](#control-(first)-contrasts) +- [Control (Last) Contrasts](#control-(last)-contrasts) +- [Deviation (First) Contrasts](#deviation-(first)-contrasts) +- [Deviation (Last) Contrasts](#deviation-(last)-contrasts) +- [Helmert (Forward) Contrasts](#helmert-(forward)-contrasts) +- [Helmert (Reverse) Contrasts](#helmert-(reverse)-contrasts) +- [Repeated (Forward) Contrasts](#repeated-(forward)-contrasts) +- [Repeated (Reverse) Contrasts](#repeated-(reverse)-contrasts) +- [Difference (Forward) Contrasts](#difference-(forward)-contrasts) +- [Difference (Reverse) Contrasts](#difference-(reverse)-contrasts) + +------------------------------------------------------------------------ ### The Data -For the sake of example, this site uses the following data. +For the sake of example, this site uses the following data. For +reference, the group means are displayed. -```r +``` r mtcars ``` -``` -## mpg cyl disp hp drat wt qsec vs am gear carb -## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 -## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 -## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 -## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 -## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 -## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 -## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 -## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 -## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 -## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 -## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 -## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 -## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 -## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 -## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 -## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 -## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 -## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 -## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 -## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 -## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 -## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 -## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 -## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 -## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 -## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 -## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 -## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 -## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 -## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 -## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 -## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 -``` - -For reference, the group means are displayed. - -```r + ## mpg cyl disp hp drat wt qsec vs am gear carb + ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 + ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 + ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 + ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 + ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 + ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 + ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 + ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 + ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 + ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 + ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 + ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 + ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 + ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 + ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 + ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 + ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 + ## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 + ## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 + ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 + ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 + ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 + ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 + ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 + ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 + ## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 + ## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 + ## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 + ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 + ## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 + ## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 + ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 + +``` r mtcars$cyl <- factor(mtcars$cyl) +summary(lm(mpg~cyl,data=mtcars)) +``` + + ## + ## Call: + ## lm(formula = mpg ~ cyl, data = mtcars) + ## + ## Residuals: + ## Min 1Q Median 3Q Max + ## -5.2636 -1.8357 0.0286 1.3893 7.2364 + ## + ## Coefficients: + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 26.6636 0.9718 27.437 < 2e-16 *** + ## cyl6 -6.9208 1.5583 -4.441 0.000119 *** + ## cyl8 -11.5636 1.2986 -8.905 8.57e-10 *** + ## --- + ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 + ## + ## Residual standard error: 3.223 on 29 degrees of freedom + ## Multiple R-squared: 0.7325, Adjusted R-squared: 0.714 + ## F-statistic: 39.7 on 2 and 29 DF, p-value: 4.979e-09 + +``` r tapply(mtcars$mpg,mtcars$cyl,mean) ``` -``` -## 4 6 8 -## 26.66364 19.74286 15.10000 -``` -### Treatment (First) Contrasts + ## 4 6 8 + ## 26.66364 19.74286 15.10000 +### Treatment (First) Contrasts -```r +``` r contrasts(mtcars$cyl) <- treatment.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 -## cyl2-1 -6.920779 1.5583482 -4.441099 1.194696e-04 -## cyl3-1 -11.563636 1.2986235 -8.904534 8.568209e-10 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 + ## cyl6-4 -6.920779 1.5583482 -4.441099 1.194696e-04 + ## cyl8-4 -11.563636 1.2986235 -8.904534 8.568209e-10 -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the first group. +As specified, the intercept is equivalent to the mean of the first +group. The additional parameters represent the difference between each +group and the first group. ### Treatment (Last) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- treatment.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 15.100000 0.8614094 17.529412 5.660681e-17 -## cyl1-3 11.563636 1.2986235 8.904534 8.568209e-10 -## cyl2-3 4.642857 1.4920048 3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 15.100000 0.8614094 17.529412 5.660681e-17 + ## cyl4-8 11.563636 1.2986235 8.904534 8.568209e-10 + ## cyl6-8 4.642857 1.4920048 3.111825 4.152209e-03 -The intercept is equivalent to the mean of the last group. Parameters represent the difference between each group and the last group. +As specified, the intercept is equivalent to the mean of the last group. +The additional parameters represent the difference between each group +and the last group. ### Control (First) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- control.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 -## cyl2-1 -6.920779 1.5583482 -4.441099 1.194696e-04 -## cyl3-1 -11.563636 1.2986235 -8.904534 8.568209e-10 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 + ## cyl6-4 -6.920779 1.5583482 -4.441099 1.194696e-04 + ## cyl8-4 -11.563636 1.2986235 -8.904534 8.568209e-10 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the first group. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the first group. ### Control (Last) Contrasts -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the last group. - - -```r +``` r contrasts(mtcars$cyl) <- control.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 -## cyl1-3 11.563636 1.2986235 8.904534 8.568209e-10 -## cyl2-3 4.642857 1.4920048 3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 + ## cyl4-8 11.563636 1.2986235 8.904534 8.568209e-10 + ## cyl6-8 4.642857 1.4920048 3.111825 4.152209e-03 -### Deviation (First) Contrasts +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the last group. +### Deviation (First) Contrasts -```r +``` r contrasts(mtcars$cyl) <- deviation.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.5021645 0.5935276 34.5428996 4.102221e-25 -## cylMD2 -0.7593074 0.9203038 -0.8250616 4.160721e-01 -## cylMD3 -5.4021645 0.7743494 -6.9763911 1.139163e-07 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.5021645 0.5935276 34.5428996 4.102221e-25 + ## cylMD2 -0.7593074 0.9203038 -0.8250616 4.160721e-01 + ## cylMD3 -5.4021645 0.7743494 -6.9763911 1.139163e-07 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The first group is not compared. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the grand mean. The first group is not compared. ### Deviation (Last) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- deviation.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.5021645 0.5935276 34.5428996 4.102221e-25 -## cylMD1 6.1614719 0.8167460 7.5439269 2.574044e-08 -## cylMD2 -0.7593074 0.9203038 -0.8250616 4.160721e-01 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.5021645 0.5935276 34.5428996 4.102221e-25 + ## cyl1 6.1614719 0.8167460 7.5439269 2.574044e-08 + ## cyl2 -0.7593074 0.9203038 -0.8250616 4.160721e-01 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the grand mean. The last group is not compared. ### Helmert (Forward) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- helmert.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 -## cylFH1 9.242208 1.2251189 7.543927 2.574044e-08 -## cylFH2 4.642857 1.4920048 3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 + ## cylFH1 9.242208 1.2251189 7.543927 2.574044e-08 + ## cylFH2 4.642857 1.4920048 3.111825 4.152209e-03 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the mean of the subsequent groups. ### Helmert (Reverse) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- helmert.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 -## cylH2 -6.920779 1.5583482 -4.441099 1.194696e-04 -## cylH3 -8.103247 1.1615242 -6.976391 1.139163e-07 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 + ## cylRH2 -6.920779 1.5583482 -4.441099 1.194696e-04 + ## cylRH3 -8.103247 1.1615242 -6.976391 1.139163e-07 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the previous groups. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the mean of the previous groups. ### Repeated (Forward) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- repeated.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 -## cyl1-2 6.920779 1.5583482 4.441099 1.194696e-04 -## cyl2-3 4.642857 1.4920048 3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 + ## cyl4-6 6.920779 1.5583482 4.441099 1.194696e-04 + ## cyl6-8 4.642857 1.4920048 3.111825 4.152209e-03 -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the subsequent group. +As specified, the intercept is equivalent to the mean of the first +group. The additional parameters represent the difference between each +group and the subsequent group. ### Repeated (Reverse) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- repeated.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 -## cyl2-1 -6.920779 1.5583482 -4.441099 1.194696e-04 -## cyl3-2 -4.642857 1.4920048 -3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 + ## cyl6-4 -6.920779 1.5583482 -4.441099 1.194696e-04 + ## cyl8-6 -4.642857 1.4920048 -3.111825 4.152209e-03 -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the previous group. +As specified, the intercept is equivalent to the mean of the first +group. The additional parameters represent the difference between each +group and the previous group. ### Difference (Forward) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- difference.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 -## cyl1-2 6.920779 1.5583482 4.441099 1.194696e-04 -## cyl2-3 4.642857 1.4920048 3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 + ## cyl4-6 6.920779 1.5583482 4.441099 1.194696e-04 + ## cyl6-8 4.642857 1.4920048 3.111825 4.152209e-03 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the subsequent group. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the subsequent group. ### Difference (Reverse) Contrasts - -```r +``` r contrasts(mtcars$cyl) <- difference.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 -## cyl2-1 -6.920779 1.5583482 -4.441099 1.194696e-04 -## cyl3-2 -4.642857 1.4920048 -3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.502165 0.5935276 34.542900 4.102221e-25 + ## cyl6-4 -6.920779 1.5583482 -4.441099 1.194696e-04 + ## cyl8-6 -4.642857 1.4920048 -3.111825 4.152209e-03 -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the previous group. +As specified, the intercept is equivalent to the mean of the group +means. The additional parameters represent the difference between each +group and the previous group. diff --git a/docs/usingCustomCodes.md b/docs/usingCustomCodes.md index d849ada..d89a04a 100644 --- a/docs/usingCustomCodes.md +++ b/docs/usingCustomCodes.md @@ -1,68 +1,97 @@ -## Using Custom Contrast Codes in Linear Models +## Using Custom Contrast Codes -**CALM** also makes it possible to develop custom codes to test specific hypotheses. The examples below use custom codes in the context of a General Linear Model to test the associated hypotheses. +**CALM** also makes it possible to develop custom codes to test specific +hypotheses. The examples below use custom codes in the context of a +General Linear Model to test the associated hypotheses. + +- [The Data](#the-data) +- [Orthogonal Contrasts](#orthogonal-contrasts) +- [Nonorthogonal Contrasts](#nonorthogonal-contrasts) + +------------------------------------------------------------------------ ### The Data -For the sake of example, this site uses the following data. +For the sake of example, this site uses the following data. For +reference, the group means are displayed. -```r +``` r mtcars ``` -``` -## mpg cyl disp hp drat wt qsec vs am gear carb -## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 -## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 -## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 -## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 -## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 -## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 -## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 -## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 -## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 -## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 -## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 -## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 -## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 -## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 -## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 -## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 -## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 -## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 -## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 -## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 -## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 -## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 -## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 -## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 -## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 -## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 -## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 -## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 -## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 -## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 -## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 -## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 -``` - -For reference, the group means are displayed. - -```r + ## mpg cyl disp hp drat wt qsec vs am gear carb + ## Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 + ## Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 + ## Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 + ## Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 + ## Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 + ## Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 + ## Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 + ## Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 + ## Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 + ## Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 + ## Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 + ## Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 + ## Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 + ## Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 + ## Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 + ## Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 + ## Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 + ## Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 + ## Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 + ## Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 + ## Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 + ## Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 + ## AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 + ## Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 + ## Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 + ## Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 + ## Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 + ## Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 + ## Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 + ## Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 + ## Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 + ## Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2 + +``` r mtcars$cyl <- factor(mtcars$cyl) +summary(lm(mpg~cyl,data=mtcars)) +``` + + ## + ## Call: + ## lm(formula = mpg ~ cyl, data = mtcars) + ## + ## Residuals: + ## Min 1Q Median 3Q Max + ## -5.2636 -1.8357 0.0286 1.3893 7.2364 + ## + ## Coefficients: + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 26.6636 0.9718 27.437 < 2e-16 *** + ## cyl6 -6.9208 1.5583 -4.441 0.000119 *** + ## cyl8 -11.5636 1.2986 -8.905 8.57e-10 *** + ## --- + ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 + ## + ## Residual standard error: 3.223 on 29 degrees of freedom + ## Multiple R-squared: 0.7325, Adjusted R-squared: 0.714 + ## F-statistic: 39.7 on 2 and 29 DF, p-value: 4.979e-09 + +``` r tapply(mtcars$mpg,mtcars$cyl,mean) ``` -``` -## 4 6 8 -## 26.66364 19.74286 15.10000 -``` + ## 4 6 8 + ## 26.66364 19.74286 15.10000 ### Orthogonal Contrasts +Here, the custom hypotheses a specified and then `CALM` is used to +create the proper codes. -```r +``` r GM <- c(1/3,1/3,1/3) H1 <- c(1,-1/2,-1/2) H2 <- c(0,1,-1) @@ -71,32 +100,32 @@ custom.orthogonal <- calm.encode(ex_custom.orthogonal) custom.orthogonal ``` -``` -## GM H1 H2 -## GROUP 1 1 0.6667 0.0 -## GROUP 2 1 -0.3333 0.5 -## GROUP 3 1 -0.3333 -0.5 -``` - + ## GM H1 H2 + ## GROUP 1 1 0.6667 0.0 + ## GROUP 2 1 -0.3333 0.5 + ## GROUP 3 1 -0.3333 -0.5 -```r -contrasts(mtcars$cyl) = custom.orthogonal[,-1] +``` r +contrasts(mtcars$cyl) <- custom.orthogonal[,-1] summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 20.501856 0.5935308 34.542197 4.104586e-25 -## cylH1 9.242208 1.2251189 7.543927 2.574044e-08 -## cylH2 4.642857 1.4920048 3.111825 4.152209e-03 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 20.501856 0.5935308 34.542197 4.104586e-25 + ## cylH1 9.242208 1.2251189 7.543927 2.574044e-08 + ## cylH2 4.642857 1.4920048 3.111825 4.152209e-03 -In this custom example, the intercept is equivalent to the mean of the group means. The first parameter represents the difference between the first group and mean of the subsequent groups. The second parameter represents the difference between the second and third groups. +In this custom example, the intercept is equivalent to the mean of the +group means. The first parameter represents the difference between the +first group and mean of the subsequent groups. The second parameter +represents the difference between the second and third groups. ### Nonorthogonal Contrasts +Again, the custom hypotheses a specified and then `CALM` is used to +create the proper codes. -```r +``` r GM <- c(1,0,0) H1 <- c(1,-1/2,-1/2) H2 <- c(1,-1,0) @@ -105,24 +134,22 @@ custom.nonorthogonal <- calm.encode(ex_custom.nonorthogonal) custom.nonorthogonal ``` -``` -## GM H1 H2 -## GROUP 1 1 0 0 -## GROUP 2 1 0 -1 -## GROUP 3 1 -2 1 -``` - + ## GM H1 H2 + ## GROUP 1 1 0 0 + ## GROUP 2 1 0 -1 + ## GROUP 3 1 -2 1 -```r +``` r contrasts(mtcars$cyl) <- custom.nonorthogonal[,-1] summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -``` -## Estimate Std. Error t value Pr(>|t|) -## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 -## cylH1 9.242208 1.2251189 7.543927 2.574044e-08 -## cylH2 6.920779 1.5583482 4.441099 1.194696e-04 -``` + ## Estimate Std. Error t value Pr(>|t|) + ## (Intercept) 26.663636 0.9718008 27.437347 2.688358e-22 + ## cylH1 9.242208 1.2251189 7.543927 2.574044e-08 + ## cylH2 6.920779 1.5583482 4.441099 1.194696e-04 -In this custom example, the intercept is equivalent to the mean of the first group. The first parameter represents the difference between the first group and mean of the subsequent groups. The second parameter represents the difference between the first and second groups. +In this custom example, the intercept is equivalent to the mean of the +first group. The first parameter represents the difference between the +first group and mean of the subsequent groups. The second parameter +represents the difference between the first and second groups. diff --git a/docs/vignettes/extractingBaseCodes.Rmd b/docs/vignettes/extractingBaseCodes.Rmd index b155f17..749808b 100644 --- a/docs/vignettes/extractingBaseCodes.Rmd +++ b/docs/vignettes/extractingBaseCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Extracting from R BAse Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Extracting from R Base Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,52 +28,69 @@ library(CALM) The package takes matrix input of the coding pattern (columns represent coded vectors, rows represent the groups being represented) and outputs the linear contrasts hypotheses being represented (the rows represent the weights for the contrast, the columns represent the groups being compared). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### contr.treatment +Specify that we wish to examine the existing `contr.treatment` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.treatment <- cbind(Int=1,contr.treatment(3)) ex_contr.treatment calm.decode(ex_contr.treatment) ``` -The intercept is equivalent to the mean of the first group. Parameter represent the difference between each group and the first group. +This shows that the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the first group. ### contr.SAS +Specify that we wish to examine the existing `contr.SAS` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.SAS <- cbind(Int=1,contr.SAS(3)) ex_contr.SAS calm.decode(ex_contr.SAS) ``` -The intercept is equivalent to the mean of the last group. Parameter represent the difference between each group and the last group. +This shows that the intercept is equivalent to the mean of the last group. The additional parameters represent the difference between each group and the last group. ### contr.sum +Specify that we wish to examine the existing `contr.sum` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.sum <- cbind(Int=1,contr.sum(3)) ex_contr.sum calm.decode(ex_contr.sum) ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +This shows that the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ### contr.helmert +Specify that we wish to examine the existing `contr.herlmert` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.helmert <- cbind(Int=1,contr.helmert(3)) ex_contr.helmert calm.decode(ex_contr.helmert) ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +This shows that the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the mean of the subsequent groups. ### contr.poly +Specify that we wish to examine the existing `contr.poly` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.poly <- cbind(Int=1,contr.poly(3)) ex_contr.poly calm.decode(ex_contr.poly) ``` -The intercept is equivalent to the mean of the group means. Parameters represent polynomial trends (linear, quadratic, etc.). +THis shows that the intercept is equivalent to the mean of the group means. The additional parameters represent polynomial trends (linear, quadratic, etc.). diff --git a/docs/vignettes/extractingRegressionCodes.Rmd b/docs/vignettes/extractingRegressionCodes.Rmd index f8daf7c..2ecae67 100644 --- a/docs/vignettes/extractingRegressionCodes.Rmd +++ b/docs/vignettes/extractingRegressionCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Extracting from Regression Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Extracting from Regression Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,8 +28,17 @@ library(CALM) The package takes matrix input of the coding pattern (columns represent coded vectors, rows represent the groups being represented) and outputs the linear contrasts hypotheses being represented (the rows represent the weights for the contrast, the columns represent the groups being compared). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### Dummy Coding +Specify a matrix of dummy codes and then use CALM to decode it into hypotheses. + ```{r} ex_dummy <- matrix(c( 1,1,0, @@ -47,10 +49,12 @@ ex_dummy <- matrix(c( calm.decode(ex_dummy) ``` -The intercept is equivalent to the mean of the last group. Parameters represent the difference between each group and the last group. +This shows that the intercept is equivalent to the mean of the last group. THe additional parameters represent the difference between each group and the last group. ### Effect Coding +Specify a matrix of effect codes and then use CALM to decode it into hypotheses. + ```{r} ex_effect <- matrix(c( 1,1,0, @@ -61,10 +65,12 @@ ex_effect <- matrix(c( calm.decode(ex_effect) ``` -The intercept is equivalent to the mean of the group means. Parameter represent the difference between each group and the grand mean. The last group is not compared. +This shows that the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ### Repeated Coding +Specify a matrix of repeated codes and then use CALM to decode it into hypotheses. + ```{r} ex_repeated <- matrix(c( 1,0,0, @@ -75,4 +81,4 @@ ex_repeated <- matrix(c( calm.decode(ex_repeated) ``` -The intercept is equivalent to the mean of the first group. Parameter represent the difference between each group and the previous group. +This shows that the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the previous group. diff --git a/docs/vignettes/producingCommonCodes.Rmd b/docs/vignettes/producingCommonCodes.Rmd index 554a14f..3b2ad08 100644 --- a/docs/vignettes/producingCommonCodes.Rmd +++ b/docs/vignettes/producingCommonCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Producing Common Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Producing Common Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,9 +28,16 @@ library(CALM) The package takes linear contrast weights (rows represented the weights for the groups, columns represent the different groups) and provides the coding pattern (where columns represent vector codes, rows represent the groups). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### Treatment (First) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the first group. +For this set of hypotheses, the intercept is equivalent to mean of the first group. The additional parameters represent the difference between each group and the first group. ```{r} M1 <- c(1,0,0) @@ -49,7 +49,7 @@ calm.encode(ex_treatment.first) ### Treatment (Last) Contrasts -The intercept is equivalent to mean of the last group. Parameters represent the difference between each group and the last group. +For this set of hypotheses, the intercept is equivalent to mean of the last group. The additional parameters represent the difference between each group and the last group. ```{r} M3 <- c(0,0,1) @@ -61,7 +61,7 @@ calm.encode(ex_treatment.last) ### Control (First) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the first group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the first group. ```{r} GM <- c(1/3,1/3,1/3) @@ -73,7 +73,7 @@ calm.encode(ex_control.first) ### Control (Last) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the last group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the last group. ```{r} GM <- c(1/3,1/3,1/3) @@ -85,7 +85,7 @@ calm.encode(ex_control.last) ### Deviation (First) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the grand mean. The first group is not compared. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the grand mean. The first group is not compared. ```{r} GM <- c(1/3,1/3,1/3) @@ -97,7 +97,7 @@ calm.encode(ex_deviation.first) ### Deviation (Last) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ```{r} GM <- c(1/3,1/3,1/3) @@ -109,7 +109,7 @@ calm.encode(ex_deviation.last) ### Helmert (Forward) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the mean of the subsequent groups. ```{r} GM <- c(1/3,1/3,1/3) @@ -121,7 +121,7 @@ calm.encode(ex_helmert.forward) ### Helmert (Reverse) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the mean of the previous groups. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the mean of the previous groups. ```{r} GM <- c(1/3,1/3,1/3) @@ -133,7 +133,7 @@ calm.encode(ex_helmert.reverse) ### Repeated (Forward) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the subsequent group. +For this set of hypotheses, the intercept is equivalent to mean of the first group. The additional parameters represent the difference between each group and the subsequent group. ```{r} M1 <- c(1,0,0) @@ -145,7 +145,7 @@ calm.encode(ex_repeated.forward) ### Repeated (Reverse) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the previous group. +For this set of hypotheses, the intercept is equivalent to mean of the first group. The additional parameters represent the difference between each group and the previous group. ```{r} M1 <- c(1,0,0) @@ -157,7 +157,7 @@ calm.encode(ex_repeated.reverse) ### Difference (Forward) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the subsequent group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the subsequent group. ```{r} GM <- c(1/3,1/3,1/3) @@ -169,7 +169,7 @@ calm.encode(ex_difference.forward) ### Difference (Reverse) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the previous group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the previous group. ```{r} GM <- c(1/3,1/3,1/3) diff --git a/docs/vignettes/producingCustomCodes.Rmd b/docs/vignettes/producingCustomCodes.Rmd index 8c391c5..d42881b 100644 --- a/docs/vignettes/producingCustomCodes.Rmd +++ b/docs/vignettes/producingCustomCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Producing Custom Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Producing Custom Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,6 +28,13 @@ library(CALM) The package takes linear contrast weights (rows represented the weights for the groups, columns represent the different groups) and provides the coding pattern (where columns represent vector codes, rows represent the groups). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### Orthogonal Contrasts In this custom example, the intercept is equivalent to mean of the group means. The first parameter represents the difference between the first group and mean of the subsequent groups. The second parameter represents the difference between the second and third groups. diff --git a/docs/vignettes/usingCommonCodes.Rmd b/docs/vignettes/usingCommonCodes.Rmd index 7bd6180..0a1c728 100644 --- a/docs/vignettes/usingCommonCodes.Rmd +++ b/docs/vignettes/usingCommonCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Using Common Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Using Common Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -33,6 +26,13 @@ library(CALM) **CALM** includes a complete set of commonly used coding schemes that can be used directly in linear model specifications. The examples below use the built-in codes in the context of a General Linear Model to test the associated hypotheses. +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### The Data For the sake of example, this site uses the following data. For reference, the group means are displayed. @@ -43,6 +43,7 @@ mtcars$cyl <- factor(mtcars$cyl) summary(lm(mpg~cyl,data=mtcars)) tapply(mtcars$mpg,mtcars$cyl,mean) ``` + ### Treatment (First) Contrasts ```{r} @@ -50,7 +51,7 @@ contrasts(mtcars$cyl) <- treatment.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the first group. +As specified, the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the first group. ### Treatment (Last) Contrasts @@ -59,7 +60,7 @@ contrasts(mtcars$cyl) <- treatment.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the last group. Parameters represent the difference between each group and the last group. +As specified, the intercept is equivalent to the mean of the last group. The additional parameters represent the difference between each group and the last group. ### Control (First) Contrasts @@ -68,17 +69,17 @@ contrasts(mtcars$cyl) <- control.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the first group. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the first group. ### Control (Last) Contrasts -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the last group. - ```{r} contrasts(mtcars$cyl) <- control.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the last group. + ### Deviation (First) Contrasts ```{r} @@ -86,7 +87,7 @@ contrasts(mtcars$cyl) <- deviation.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The first group is not compared. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The first group is not compared. ### Deviation (Last) Contrasts @@ -95,7 +96,7 @@ contrasts(mtcars$cyl) <- deviation.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ### Helmert (Forward) Contrasts @@ -104,7 +105,7 @@ contrasts(mtcars$cyl) <- helmert.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the mean of the subsequent groups. ### Helmert (Reverse) Contrasts @@ -113,7 +114,7 @@ contrasts(mtcars$cyl) <- helmert.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the previous groups. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the mean of the previous groups. ### Repeated (Forward) Contrasts @@ -122,7 +123,7 @@ contrasts(mtcars$cyl) <- repeated.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the subsequent group. +As specified, the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the subsequent group. ### Repeated (Reverse) Contrasts @@ -131,7 +132,7 @@ contrasts(mtcars$cyl) <- repeated.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the previous group. +As specified, the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the previous group. ### Difference (Forward) Contrasts @@ -140,7 +141,7 @@ contrasts(mtcars$cyl) <- difference.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the subsequent group. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the subsequent group. ### Difference (Reverse) Contrasts @@ -149,4 +150,4 @@ contrasts(mtcars$cyl) <- difference.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the previous group. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the previous group. diff --git a/docs/vignettes/usingCustomCodes.Rmd b/docs/vignettes/usingCustomCodes.Rmd index 39c25c4..63d639d 100644 --- a/docs/vignettes/usingCustomCodes.Rmd +++ b/docs/vignettes/usingCustomCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "using Common Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Using Custom Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -33,6 +26,13 @@ library(CALM) **CALM** also makes it possible to develop custom codes to test specific hypotheses. The examples below use custom codes in the context of a General Linear Model to test the associated hypotheses. +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### The Data For the sake of example, this site uses the following data. For reference, the group means are displayed. @@ -46,6 +46,8 @@ tapply(mtcars$mpg,mtcars$cyl,mean) ### Orthogonal Contrasts +Here, the custom hypotheses a specified and then `CALM` is used to create the proper codes. + ```{r} GM <- c(1/3,1/3,1/3) H1 <- c(1,-1/2,-1/2) @@ -56,7 +58,7 @@ custom.orthogonal ``` ```{r} -contrasts(mtcars$cyl) = custom.orthogonal[,-1] +contrasts(mtcars$cyl) <- custom.orthogonal[,-1] summary(lm(mpg~cyl,data=mtcars))$coefficients ``` @@ -64,6 +66,8 @@ In this custom example, the intercept is equivalent to the mean of the group mea ### Nonorthogonal Contrasts +Again, the custom hypotheses a specified and then `CALM` is used to create the proper codes. + ```{r} GM <- c(1,0,0) H1 <- c(1,-1/2,-1/2) diff --git a/vignettes/extractingBaseCodes.Rmd b/vignettes/extractingBaseCodes.Rmd index b155f17..749808b 100644 --- a/vignettes/extractingBaseCodes.Rmd +++ b/vignettes/extractingBaseCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Extracting from R BAse Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Extracting from R Base Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,52 +28,69 @@ library(CALM) The package takes matrix input of the coding pattern (columns represent coded vectors, rows represent the groups being represented) and outputs the linear contrasts hypotheses being represented (the rows represent the weights for the contrast, the columns represent the groups being compared). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### contr.treatment +Specify that we wish to examine the existing `contr.treatment` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.treatment <- cbind(Int=1,contr.treatment(3)) ex_contr.treatment calm.decode(ex_contr.treatment) ``` -The intercept is equivalent to the mean of the first group. Parameter represent the difference between each group and the first group. +This shows that the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the first group. ### contr.SAS +Specify that we wish to examine the existing `contr.SAS` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.SAS <- cbind(Int=1,contr.SAS(3)) ex_contr.SAS calm.decode(ex_contr.SAS) ``` -The intercept is equivalent to the mean of the last group. Parameter represent the difference between each group and the last group. +This shows that the intercept is equivalent to the mean of the last group. The additional parameters represent the difference between each group and the last group. ### contr.sum +Specify that we wish to examine the existing `contr.sum` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.sum <- cbind(Int=1,contr.sum(3)) ex_contr.sum calm.decode(ex_contr.sum) ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +This shows that the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ### contr.helmert +Specify that we wish to examine the existing `contr.herlmert` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.helmert <- cbind(Int=1,contr.helmert(3)) ex_contr.helmert calm.decode(ex_contr.helmert) ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +This shows that the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the mean of the subsequent groups. ### contr.poly +Specify that we wish to examine the existing `contr.poly` and then use CALM to decode it into hypotheses. + ```{r} ex_contr.poly <- cbind(Int=1,contr.poly(3)) ex_contr.poly calm.decode(ex_contr.poly) ``` -The intercept is equivalent to the mean of the group means. Parameters represent polynomial trends (linear, quadratic, etc.). +THis shows that the intercept is equivalent to the mean of the group means. The additional parameters represent polynomial trends (linear, quadratic, etc.). diff --git a/vignettes/extractingRegressionCodes.Rmd b/vignettes/extractingRegressionCodes.Rmd index f8daf7c..2ecae67 100644 --- a/vignettes/extractingRegressionCodes.Rmd +++ b/vignettes/extractingRegressionCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Extracting from Regression Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Extracting from Regression Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,8 +28,17 @@ library(CALM) The package takes matrix input of the coding pattern (columns represent coded vectors, rows represent the groups being represented) and outputs the linear contrasts hypotheses being represented (the rows represent the weights for the contrast, the columns represent the groups being compared). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### Dummy Coding +Specify a matrix of dummy codes and then use CALM to decode it into hypotheses. + ```{r} ex_dummy <- matrix(c( 1,1,0, @@ -47,10 +49,12 @@ ex_dummy <- matrix(c( calm.decode(ex_dummy) ``` -The intercept is equivalent to the mean of the last group. Parameters represent the difference between each group and the last group. +This shows that the intercept is equivalent to the mean of the last group. THe additional parameters represent the difference between each group and the last group. ### Effect Coding +Specify a matrix of effect codes and then use CALM to decode it into hypotheses. + ```{r} ex_effect <- matrix(c( 1,1,0, @@ -61,10 +65,12 @@ ex_effect <- matrix(c( calm.decode(ex_effect) ``` -The intercept is equivalent to the mean of the group means. Parameter represent the difference between each group and the grand mean. The last group is not compared. +This shows that the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ### Repeated Coding +Specify a matrix of repeated codes and then use CALM to decode it into hypotheses. + ```{r} ex_repeated <- matrix(c( 1,0,0, @@ -75,4 +81,4 @@ ex_repeated <- matrix(c( calm.decode(ex_repeated) ``` -The intercept is equivalent to the mean of the first group. Parameter represent the difference between each group and the previous group. +This shows that the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the previous group. diff --git a/vignettes/producingCommonCodes.Rmd b/vignettes/producingCommonCodes.Rmd index 554a14f..3b2ad08 100644 --- a/vignettes/producingCommonCodes.Rmd +++ b/vignettes/producingCommonCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Producing Common Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Producing Common Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,9 +28,16 @@ library(CALM) The package takes linear contrast weights (rows represented the weights for the groups, columns represent the different groups) and provides the coding pattern (where columns represent vector codes, rows represent the groups). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### Treatment (First) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the first group. +For this set of hypotheses, the intercept is equivalent to mean of the first group. The additional parameters represent the difference between each group and the first group. ```{r} M1 <- c(1,0,0) @@ -49,7 +49,7 @@ calm.encode(ex_treatment.first) ### Treatment (Last) Contrasts -The intercept is equivalent to mean of the last group. Parameters represent the difference between each group and the last group. +For this set of hypotheses, the intercept is equivalent to mean of the last group. The additional parameters represent the difference between each group and the last group. ```{r} M3 <- c(0,0,1) @@ -61,7 +61,7 @@ calm.encode(ex_treatment.last) ### Control (First) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the first group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the first group. ```{r} GM <- c(1/3,1/3,1/3) @@ -73,7 +73,7 @@ calm.encode(ex_control.first) ### Control (Last) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the last group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the last group. ```{r} GM <- c(1/3,1/3,1/3) @@ -85,7 +85,7 @@ calm.encode(ex_control.last) ### Deviation (First) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the grand mean. The first group is not compared. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the grand mean. The first group is not compared. ```{r} GM <- c(1/3,1/3,1/3) @@ -97,7 +97,7 @@ calm.encode(ex_deviation.first) ### Deviation (Last) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ```{r} GM <- c(1/3,1/3,1/3) @@ -109,7 +109,7 @@ calm.encode(ex_deviation.last) ### Helmert (Forward) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the mean of the subsequent groups. ```{r} GM <- c(1/3,1/3,1/3) @@ -121,7 +121,7 @@ calm.encode(ex_helmert.forward) ### Helmert (Reverse) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the mean of the previous groups. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the mean of the previous groups. ```{r} GM <- c(1/3,1/3,1/3) @@ -133,7 +133,7 @@ calm.encode(ex_helmert.reverse) ### Repeated (Forward) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the subsequent group. +For this set of hypotheses, the intercept is equivalent to mean of the first group. The additional parameters represent the difference between each group and the subsequent group. ```{r} M1 <- c(1,0,0) @@ -145,7 +145,7 @@ calm.encode(ex_repeated.forward) ### Repeated (Reverse) Contrasts -The intercept is equivalent to mean of the first group. Parameters represent the difference between each group and the previous group. +For this set of hypotheses, the intercept is equivalent to mean of the first group. The additional parameters represent the difference between each group and the previous group. ```{r} M1 <- c(1,0,0) @@ -157,7 +157,7 @@ calm.encode(ex_repeated.reverse) ### Difference (Forward) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the subsequent group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the subsequent group. ```{r} GM <- c(1/3,1/3,1/3) @@ -169,7 +169,7 @@ calm.encode(ex_difference.forward) ### Difference (Reverse) Contrasts -The intercept is equivalent to mean of the group means. Parameters represent the difference between each group and the previous group. +For this set of hypotheses, the intercept is equivalent to mean of the group means. The additional parameters represent the difference between each group and the previous group. ```{r} GM <- c(1/3,1/3,1/3) diff --git a/vignettes/producingCustomCodes.Rmd b/vignettes/producingCustomCodes.Rmd index 8c391c5..d42881b 100644 --- a/vignettes/producingCustomCodes.Rmd +++ b/vignettes/producingCustomCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Producing Custom Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Producing Custom Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -35,6 +28,13 @@ library(CALM) The package takes linear contrast weights (rows represented the weights for the groups, columns represent the different groups) and provides the coding pattern (where columns represent vector codes, rows represent the groups). +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### Orthogonal Contrasts In this custom example, the intercept is equivalent to mean of the group means. The first parameter represents the difference between the first group and mean of the subsequent groups. The second parameter represents the difference between the second and third groups. diff --git a/vignettes/usingCommonCodes.Rmd b/vignettes/usingCommonCodes.Rmd index 7bd6180..0a1c728 100644 --- a/vignettes/usingCommonCodes.Rmd +++ b/vignettes/usingCommonCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "Using Common Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Using Common Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -33,6 +26,13 @@ library(CALM) **CALM** includes a complete set of commonly used coding schemes that can be used directly in linear model specifications. The examples below use the built-in codes in the context of a General Linear Model to test the associated hypotheses. +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### The Data For the sake of example, this site uses the following data. For reference, the group means are displayed. @@ -43,6 +43,7 @@ mtcars$cyl <- factor(mtcars$cyl) summary(lm(mpg~cyl,data=mtcars)) tapply(mtcars$mpg,mtcars$cyl,mean) ``` + ### Treatment (First) Contrasts ```{r} @@ -50,7 +51,7 @@ contrasts(mtcars$cyl) <- treatment.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the first group. +As specified, the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the first group. ### Treatment (Last) Contrasts @@ -59,7 +60,7 @@ contrasts(mtcars$cyl) <- treatment.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the last group. Parameters represent the difference between each group and the last group. +As specified, the intercept is equivalent to the mean of the last group. The additional parameters represent the difference between each group and the last group. ### Control (First) Contrasts @@ -68,17 +69,17 @@ contrasts(mtcars$cyl) <- control.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the first group. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the first group. ### Control (Last) Contrasts -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the last group. - ```{r} contrasts(mtcars$cyl) <- control.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the last group. + ### Deviation (First) Contrasts ```{r} @@ -86,7 +87,7 @@ contrasts(mtcars$cyl) <- deviation.first summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The first group is not compared. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The first group is not compared. ### Deviation (Last) Contrasts @@ -95,7 +96,7 @@ contrasts(mtcars$cyl) <- deviation.last summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the grand mean. The last group is not compared. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the grand mean. The last group is not compared. ### Helmert (Forward) Contrasts @@ -104,7 +105,7 @@ contrasts(mtcars$cyl) <- helmert.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the subsequent groups. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the mean of the subsequent groups. ### Helmert (Reverse) Contrasts @@ -113,7 +114,7 @@ contrasts(mtcars$cyl) <- helmert.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the mean of the previous groups. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the mean of the previous groups. ### Repeated (Forward) Contrasts @@ -122,7 +123,7 @@ contrasts(mtcars$cyl) <- repeated.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the subsequent group. +As specified, the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the subsequent group. ### Repeated (Reverse) Contrasts @@ -131,7 +132,7 @@ contrasts(mtcars$cyl) <- repeated.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the first group. Parameters represent the difference between each group and the previous group. +As specified, the intercept is equivalent to the mean of the first group. The additional parameters represent the difference between each group and the previous group. ### Difference (Forward) Contrasts @@ -140,7 +141,7 @@ contrasts(mtcars$cyl) <- difference.forward summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the subsequent group. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the subsequent group. ### Difference (Reverse) Contrasts @@ -149,4 +150,4 @@ contrasts(mtcars$cyl) <- difference.reverse summary(lm(mpg~cyl,data=mtcars))$coefficients ``` -The intercept is equivalent to the mean of the group means. Parameters represent the difference between each group and the previous group. +As specified, the intercept is equivalent to the mean of the group means. The additional parameters represent the difference between each group and the previous group. diff --git a/vignettes/usingCustomCodes.Rmd b/vignettes/usingCustomCodes.Rmd index 39c25c4..63d639d 100644 --- a/vignettes/usingCustomCodes.Rmd +++ b/vignettes/usingCustomCodes.Rmd @@ -1,16 +1,8 @@ --- -title: "Contrast Algorithms for Linear Models" -author: "Craig A. Wendorf" -date: "`r Sys.Date()`" +subtitle: "using Common Contrast Codes" output: - html_document: - toc: true - toc_float: true - toc_depth: 4 - collapse: true - theme: cerulean - highlight: default - keep_md: TRUE + github_document: + preserve_yaml: FALSE vignette: > %\VignetteIndexEntry{Using Custom Contrast Codes} %\VignetteEngine{knitr::rmarkdown} @@ -20,6 +12,7 @@ vignette: > ```{r,include=FALSE} #suppress the warnings and other messages from showing in the knitted file. knitr::opts_chunk$set(fig.width=7, fig.height=5,fig.path='figures/',echo=TRUE,warning=FALSE,message=FALSE) +devtools::source_gist("8e6e5dc401e3fc1042ef7a030f9d19c7",filename='revised_toc.R') ``` ```{r,include=FALSE} @@ -33,6 +26,13 @@ library(CALM) **CALM** also makes it possible to develop custom codes to test specific hypotheses. The examples below use custom codes in the context of a General Linear Model to test the associated hypotheses. +```{r toc, echo=FALSE} +thisfile <- knitr::current_input() +revised_toc(thisfile,base_level=3,toc_depth=4) +``` + +--- + ### The Data For the sake of example, this site uses the following data. For reference, the group means are displayed. @@ -46,6 +46,8 @@ tapply(mtcars$mpg,mtcars$cyl,mean) ### Orthogonal Contrasts +Here, the custom hypotheses a specified and then `CALM` is used to create the proper codes. + ```{r} GM <- c(1/3,1/3,1/3) H1 <- c(1,-1/2,-1/2) @@ -56,7 +58,7 @@ custom.orthogonal ``` ```{r} -contrasts(mtcars$cyl) = custom.orthogonal[,-1] +contrasts(mtcars$cyl) <- custom.orthogonal[,-1] summary(lm(mpg~cyl,data=mtcars))$coefficients ``` @@ -64,6 +66,8 @@ In this custom example, the intercept is equivalent to the mean of the group mea ### Nonorthogonal Contrasts +Again, the custom hypotheses a specified and then `CALM` is used to create the proper codes. + ```{r} GM <- c(1,0,0) H1 <- c(1,-1/2,-1/2)