# PCA compression

This function compresses data to n-dimensions using principal component analysis (singular value decomposition) as advocated in the following papers:

* [Korhonen, Hernandez-Pavon, et al (2011) Removal of large muscle artifacts from transcranial magnetic stimulation-evoked EEG by independent component analysis. Med Biol Eng Compt, 49:397-407.](http://www.ncbi.nlm.nih.gov/pubmed/21331656)
* [Hernandez-Pavon et al (2012) Uncovering neural independent components from highly artifactual TMS-evoked EEG data. J Neurosci Meth, 209:144-57.](http://www.ncbi.nlm.nih.gov/pubmed/22687937)

In these papers, PCA compression is run before [EDM](https://nigelrogasch.gitbook.io/tesa-user-manual/remove_minimise_tms_muscle_activity/edm) and [PCA suppression](https://nigelrogasch.gitbook.io/tesa-user-manual/remove_minimise_tms_muscle_activity/pca_suppression) respectively.

&#x20;

![](https://3092694373-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmJDCxgyXG9A9GA-gSy%2F-LmJDDdbvCHG7SXDX4aP%2F-LmJDJHYJS5uF4zuVBL1%2Fpca_compression_ex.png?generation=1565854883438168\&alt=media)

**Example of output from PCA compression.** Data were compressed from 60 to 30 dimensions.

## EEGLAB user interface

![](https://3092694373-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LmJDCxgyXG9A9GA-gSy%2F-LmJDDdbvCHG7SXDX4aP%2F-LmJDJHaaUpwJVnHczbk%2Fpca_compression.png?generation=1565854884936911\&alt=media)

**1.** Enter the number of dimensions to reduce the data by.

**2.** Turn on/off a plot which summarises the variance of each principal component before and after compression.

## Scripts

### Base function

`EEG = tesa_pcacompress( EEG );` Default use.

`EEG = tesa_pcacompress( EEG , 'key1', value1...);` Custom inputs.

### Pop function

`EEG = pop_tesa_pcacompress( EEG );` Pop up window.

`EEG = pop_tesa_pcacompress( EEG , 'key1', value1...);` Custom inputs.

### Required inputs

| Input | Description          | Example | Default |
| ----- | -------------------- | ------- | ------- |
| EEG   | EEGLAB EEG structure | EEG     | -       |

### Optional inputs (key/value pairs)

| Key       | Input value   | Description                                                                   | Example | Default |
| --------- | ------------- | ----------------------------------------------------------------------------- | ------- | ------- |
| 'compVal' | integer       | Integer describes the number of components to reduce the data to.             | 40      | 30      |
| 'plot'    | 'on' or 'off' | Turns on/off plot summarising the variance explained by principal components. | 'off'   | 'on'    |

### Outputs

| Output | Description          |
| ------ | -------------------- |
| EEG    | EEGLAB EEG structure |

### Examples

`EEG = pop_tesa_pcacompress( EEG, 'compVal', 40 );` Compress to top 40 dimensions.

`EEG = pop_tesa_pcacompress( EEG, 'plot','off' );` Turns off summary plot.
