Skip to content

Commit

Permalink
Updated vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendorf committed Oct 7, 2023
1 parent 58bada6 commit 53de064
Show file tree
Hide file tree
Showing 18 changed files with 825 additions and 672 deletions.
171 changes: 93 additions & 78 deletions docs/extractingBaseCodes.md
Original file line number Diff line number Diff line change
@@ -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.).
74 changes: 48 additions & 26 deletions docs/extractingRegressionCodes.md
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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.
Loading

0 comments on commit 53de064

Please sign in to comment.