-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
66 lines (46 loc) · 1.97 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# clustRcompaR
The goal of clustRcompaR is to make it easy to cluster (or group) a series of documents (texts of any length), and to interpret these groups and to describe their frequency across factors, such as between different groups or over time.
## Installation
You can install the development version of clustRcompaR from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("alishinski/clustRcompaR")
```
You can install the stable release on CRAN with:
```{r, eval = F}
install.packages("clustRcompaR")
```
## Example
This is a basic example using the built-in inaugural addressess dataset.
First, we use `cluster()` to cluster the documents into three clusters. We include a new variable, `year_before_1900`, which we will later use to compare frequencies across clusters. Then we use `extract_terms()` to view the terms and term frequencies in the two clusters.
First, let's process the texts.
```{r example}
library(clustRcompaR)
library(dplyr)
d <- inaugural_addresses
d <- mutate(d, century = ifelse(Year < 1800, "17th",
ifelse(Year >= 1800 & Year < 1900, "18th",
ifelse(Year >= 1900 & Year < 2000, "19th", "20th"))))
```
Next, we **cluster** the texts.
```{r clustering}
three_clusters <- cluster(d, century, n_clusters = 3)
extract_terms(three_clusters)
```
Then, we use the `compare()` function to compare the frequency of clusters across a factor, in this case, the century. We can then use the `compare_plot()` or `compare_test()` (which uses a Chi-Square test) function.
Here, we can **compare** the texts.
```{r}
three_clusters_comparison <- compare(three_clusters, "century")
compare_plot(three_clusters_comparison)
```