Skip to content

Commit

Permalink
updating features section
Browse files Browse the repository at this point in the history
markolalovic committed Jul 1, 2024
1 parent a435c37 commit 543ca5b
Showing 6 changed files with 69 additions and 61 deletions.
4 changes: 3 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
@@ -54,6 +54,8 @@ To keep the package lightweight, **latent2likert** only imports [mvtnorm](https:

## Using `rlikert`

You can use the `rlikert` function to simulate Likert item responses.

To generate a sample of random responses to one item on a 5-point Likert scale, use:

```{r}
@@ -131,7 +133,7 @@ Note that, depending on the value of the skewness parameter, the normal latent d

## Related R Packages

To simulate Likert item responses, the `draw_likert` function from the [fabricatr](https://CRAN.R-project.org/package=fabricatr) package can be used to recode a latent variable into a Likert response variable by specifying intervals that subdivide the continuous range. The **latent2likert** package, however, offers an advantage by automatically calculating optimal intervals that minimize distortion between the latent variable and the Likert response variable for both normal and skew normal latent distributions, eliminating the need to manually specify the intervals.
Alternatively, you can simulate Likert item responses using the `draw_likert` function from the [fabricatr](https://CRAN.R-project.org/package=fabricatr) package. This function recodes a latent variable into a Likert response variable by specifying intervals that subdivide the continuous range. The **latent2likert** package, however, offers an advantage by automatically calculating optimal intervals that minimize distortion between the latent variable and the Likert response variable for both normal and skew normal latent distributions, eliminating the need to manually specify the intervals.

There are also several alternative approaches that do not rely on latent distributions. One method involves directly defining a discrete probability distribution and sampling from it using the `sample` function in R or the `likert` function from the [wakefield](https://CRAN.R-project.org/package=wakefield) package. Another approach is to specify the means, standard deviations, and correlations among Likert response variables. For this, you can use [LikertMakeR](https://CRAN.R-project.org/package=LikertMakeR) or [SimCorMultRes](https://CRAN.R-project.org/package=SimCorMultRes) to generate correlated multinomial responses.

42 changes: 22 additions & 20 deletions README.html
Original file line number Diff line number Diff line change
@@ -669,11 +669,13 @@ <h2 id="structure">Structure</h2>
</figure>

<h2 id="using-rlikert">Using <code>rlikert</code></h2>
<p>You can use the <code>rlikert</code> function to simulate Likert item
responses.</p>
<p>To generate a sample of random responses to one item on a 5-point
Likert scale, use:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" tabindex="-1"></a><span class="fu">library</span>(latent2likert)</span>
<span id="cb2-2"><a href="#cb2-2" tabindex="-1"></a><span class="fu">rlikert</span>(<span class="at">size =</span> <span class="dv">10</span>, <span class="at">n_items =</span> <span class="dv">1</span>, <span class="at">n_levels =</span> <span class="dv">5</span>)</span>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a><span class="co">#&gt; [1] 4 2 3 2 3 5 2 2 3 2</span></span></code></pre></div>
<span id="cb2-3"><a href="#cb2-3" tabindex="-1"></a><span class="co">#&gt; [1] 2 5 2 2 3 2 4 4 3 3</span></span></code></pre></div>
<p>To generate responses to multiple items with specified
parameters:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" tabindex="-1"></a><span class="fu">rlikert</span>(<span class="at">size =</span> <span class="dv">10</span>,</span>
@@ -683,16 +685,16 @@ <h2 id="using-rlikert">Using <code>rlikert</code></h2>
<span id="cb3-5"><a href="#cb3-5" tabindex="-1"></a> <span class="at">sd =</span> <span class="fu">c</span>(<span class="fl">0.8</span>, <span class="dv">1</span>, <span class="dv">1</span>),</span>
<span id="cb3-6"><a href="#cb3-6" tabindex="-1"></a> <span class="at">corr =</span> <span class="fl">0.5</span>)</span>
<span id="cb3-7"><a href="#cb3-7" tabindex="-1"></a><span class="co">#&gt; Y1 Y2 Y3</span></span>
<span id="cb3-8"><a href="#cb3-8" tabindex="-1"></a><span class="co">#&gt; [1,] 2 1 3</span></span>
<span id="cb3-9"><a href="#cb3-9" tabindex="-1"></a><span class="co">#&gt; [2,] 4 4 6</span></span>
<span id="cb3-10"><a href="#cb3-10" tabindex="-1"></a><span class="co">#&gt; [3,] 3 3 4</span></span>
<span id="cb3-11"><a href="#cb3-11" tabindex="-1"></a><span class="co">#&gt; [4,] 4 3 5</span></span>
<span id="cb3-12"><a href="#cb3-12" tabindex="-1"></a><span class="co">#&gt; [5,] 2 1 6</span></span>
<span id="cb3-13"><a href="#cb3-13" tabindex="-1"></a><span class="co">#&gt; [6,] 3 2 3</span></span>
<span id="cb3-14"><a href="#cb3-14" tabindex="-1"></a><span class="co">#&gt; [7,] 3 1 4</span></span>
<span id="cb3-15"><a href="#cb3-15" tabindex="-1"></a><span class="co">#&gt; [8,] 3 2 2</span></span>
<span id="cb3-16"><a href="#cb3-16" tabindex="-1"></a><span class="co">#&gt; [9,] 2 2 2</span></span>
<span id="cb3-17"><a href="#cb3-17" tabindex="-1"></a><span class="co">#&gt; [10,] 2 1 2</span></span></code></pre></div>
<span id="cb3-8"><a href="#cb3-8" tabindex="-1"></a><span class="co">#&gt; [1,] 3 4 3</span></span>
<span id="cb3-9"><a href="#cb3-9" tabindex="-1"></a><span class="co">#&gt; [2,] 1 2 1</span></span>
<span id="cb3-10"><a href="#cb3-10" tabindex="-1"></a><span class="co">#&gt; [3,] 3 1 3</span></span>
<span id="cb3-11"><a href="#cb3-11" tabindex="-1"></a><span class="co">#&gt; [4,] 2 1 3</span></span>
<span id="cb3-12"><a href="#cb3-12" tabindex="-1"></a><span class="co">#&gt; [5,] 2 1 4</span></span>
<span id="cb3-13"><a href="#cb3-13" tabindex="-1"></a><span class="co">#&gt; [6,] 2 2 5</span></span>
<span id="cb3-14"><a href="#cb3-14" tabindex="-1"></a><span class="co">#&gt; [7,] 3 2 5</span></span>
<span id="cb3-15"><a href="#cb3-15" tabindex="-1"></a><span class="co">#&gt; [8,] 1 1 2</span></span>
<span id="cb3-16"><a href="#cb3-16" tabindex="-1"></a><span class="co">#&gt; [9,] 3 2 3</span></span>
<span id="cb3-17"><a href="#cb3-17" tabindex="-1"></a><span class="co">#&gt; [10,] 2 2 3</span></span></code></pre></div>
<p>You can also provide a correlation matrix:</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a>corr <span class="ot">&lt;-</span> <span class="fu">matrix</span>(<span class="fu">c</span>(<span class="fl">1.00</span>, <span class="sc">-</span><span class="fl">0.63</span>, <span class="sc">-</span><span class="fl">0.39</span>, </span>
<span id="cb4-2"><a href="#cb4-2" tabindex="-1"></a> <span class="sc">-</span><span class="fl">0.63</span>, <span class="fl">1.00</span>, <span class="fl">0.41</span>, </span>
@@ -708,17 +710,17 @@ <h2 id="using-rlikert">Using <code>rlikert</code></h2>
and these estimates are typically lower:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" tabindex="-1"></a><span class="fu">cor</span>(data)</span>
<span id="cb5-2"><a href="#cb5-2" tabindex="-1"></a><span class="co">#&gt; Y1 Y2 Y3</span></span>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a><span class="co">#&gt; Y1 1.0000000 -0.5485779 -0.3830635</span></span>
<span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a><span class="co">#&gt; Y2 -0.5485779 1.0000000 0.3787044</span></span>
<span id="cb5-5"><a href="#cb5-5" tabindex="-1"></a><span class="co">#&gt; Y3 -0.3830635 0.3787044 1.0000000</span></span></code></pre></div>
<span id="cb5-3"><a href="#cb5-3" tabindex="-1"></a><span class="co">#&gt; Y1 1.0000000 -0.5384098 -0.3715239</span></span>
<span id="cb5-4"><a href="#cb5-4" tabindex="-1"></a><span class="co">#&gt; Y2 -0.5384098 1.0000000 0.4012943</span></span>
<span id="cb5-5"><a href="#cb5-5" tabindex="-1"></a><span class="co">#&gt; Y3 -0.3715239 0.4012943 1.0000000</span></span></code></pre></div>
<h2 id="using-estimate_params">Using <code>estimate_params</code></h2>
<p>Given the data, you can estimate the values of latent parameters
using:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" tabindex="-1"></a><span class="fu">estimate_params</span>(data, <span class="at">n_levels =</span> <span class="fu">c</span>(<span class="dv">4</span>, <span class="dv">5</span>, <span class="dv">6</span>), <span class="at">skew =</span> <span class="dv">0</span>)</span>
<span id="cb6-2"><a href="#cb6-2" tabindex="-1"></a><span class="co">#&gt; items</span></span>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a><span class="co">#&gt; estimates Y1 Y2 Y3</span></span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a><span class="co">#&gt; mean 0.002700821 -0.949328033 0.011770264</span></span>
<span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a><span class="co">#&gt; sd 0.790723208 1.017877712 0.995988467</span></span></code></pre></div>
<span id="cb6-3"><a href="#cb6-3" tabindex="-1"></a><span class="co">#&gt; estimates Y1 Y2 Y3</span></span>
<span id="cb6-4"><a href="#cb6-4" tabindex="-1"></a><span class="co">#&gt; mean -0.06292803 -0.98863044 0.10704210</span></span>
<span id="cb6-5"><a href="#cb6-5" tabindex="-1"></a><span class="co">#&gt; sd 0.81566374 1.08402520 0.95083534</span></span></code></pre></div>
<h2 id="transformation">Transformation</h2>
<p>To visualize the transformation, you can use
<code>plot_likert_transform()</code>. It plots the densities of latent
@@ -753,9 +755,9 @@ <h2 id="further-reading">Further Reading</h2>
<li>The implemented algorithms are described in the functions <a href="https://lalovic.io/latent2likert/reference/index.html">reference</a>.</li>
</ul>
<h2 id="related-r-packages">Related R Packages</h2>
<p>To simulate Likert item responses, the <code>draw_likert</code>
function from the <a href="https://CRAN.R-project.org/package=fabricatr">fabricatr</a>
package can be used to recode a latent variable into a Likert response
<p>Alternatively, you can simulate Likert item responses using the
<code>draw_likert</code> function from the <a href="https://CRAN.R-project.org/package=fabricatr">fabricatr</a>
package. This function recodes a latent variable into a Likert response
variable by specifying intervals that subdivide the continuous range.
The <strong>latent2likert</strong> package, however, offers an advantage
by automatically calculating optimal intervals that minimize distortion
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -59,13 +59,15 @@ install this dependency during interactive sessions if needed.

## Using `rlikert`

You can use the `rlikert` function to simulate Likert item responses.

To generate a sample of random responses to one item on a 5-point Likert
scale, use:

``` r
library(latent2likert)
rlikert(size = 10, n_items = 1, n_levels = 5)
#> [1] 4 2 3 2 3 5 2 2 3 2
#> [1] 2 5 2 2 3 2 4 4 3 3
```

To generate responses to multiple items with specified parameters:
@@ -78,16 +80,16 @@ rlikert(size = 10,
sd = c(0.8, 1, 1),
corr = 0.5)
#> Y1 Y2 Y3
#> [1,] 2 1 3
#> [2,] 4 4 6
#> [3,] 3 3 4
#> [4,] 4 3 5
#> [5,] 2 1 6
#> [6,] 3 2 3
#> [7,] 3 1 4
#> [8,] 3 2 2
#> [9,] 2 2 2
#> [10,] 2 1 2
#> [1,] 3 4 3
#> [2,] 1 2 1
#> [3,] 3 1 3
#> [4,] 2 1 3
#> [5,] 2 1 4
#> [6,] 2 2 5
#> [7,] 3 2 5
#> [8,] 1 1 2
#> [9,] 3 2 3
#> [10,] 2 2 3
```

You can also provide a correlation matrix:
@@ -111,9 +113,9 @@ these estimates are typically lower:
``` r
cor(data)
#> Y1 Y2 Y3
#> Y1 1.0000000 -0.5485779 -0.3830635
#> Y2 -0.5485779 1.0000000 0.3787044
#> Y3 -0.3830635 0.3787044 1.0000000
#> Y1 1.0000000 -0.5384098 -0.3715239
#> Y2 -0.5384098 1.0000000 0.4012943
#> Y3 -0.3715239 0.4012943 1.0000000
```

## Using `estimate_params`
@@ -123,9 +125,9 @@ Given the data, you can estimate the values of latent parameters using:
``` r
estimate_params(data, n_levels = c(4, 5, 6), skew = 0)
#> items
#> estimates Y1 Y2 Y3
#> mean 0.002700821 -0.949328033 0.011770264
#> sd 0.790723208 1.017877712 0.995988467
#> estimates Y1 Y2 Y3
#> mean -0.06292803 -0.98863044 0.10704210
#> sd 0.81566374 1.08402520 0.95083534
```

## Transformation
@@ -169,9 +171,10 @@ distribution is used. The value of skewness is restricted to the range

## Related R Packages

To simulate Likert item responses, the `draw_likert` function from the
[fabricatr](https://CRAN.R-project.org/package=fabricatr) package can be
used to recode a latent variable into a Likert response variable by
Alternatively, you can simulate Likert item responses using the
`draw_likert` function from the
[fabricatr](https://CRAN.R-project.org/package=fabricatr) package. This
function recodes a latent variable into a Likert response variable by
specifying intervals that subdivide the continuous range. The
**latent2likert** package, however, offers an advantage by automatically
calculating optimal intervals that minimize distortion between the
37 changes: 19 additions & 18 deletions docs/index.html
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ pkgdown: 2.0.9
pkgdown_sha: ~
articles:
using_latent2likert: using_latent2likert.html
last_built: 2024-06-25T07:50Z
last_built: 2024-07-01T10:28Z
urls:
reference: https://markolalovic.github.io/latent2likert/reference
article: https://markolalovic.github.io/latent2likert/articles
2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

0 comments on commit 543ca5b

Please sign in to comment.