-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
112 lines (86 loc) · 4.09 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# cosme
<!-- badges: start -->
[![R build status](https://github.com/sociometricresearch/cosme/workflows/R-CMD-check/badge.svg)](https://github.com/sociometricresearch/cosme/actions)
[![Codecov test coverage](https://codecov.io/gh/sociometricresearch/cosme/branch/master/graph/badge.svg)](https://codecov.io/gh/sociometricresearch/cosme?branch=master)
[![DOI](https://zenodo.org/badge/198222115.svg)](https://zenodo.org/badge/latestdoi/198222115)
[![CRAN status](https://www.r-pkg.org/badges/version/cosme)](https://cran.r-project.org/package=cosme)
<!-- badges: end -->
The `cosme` package allows you to calculate several estimations of the quality of your survey questions and also adjust your estimations for measurement error.
Assuming you have a data frame with the `reliability`, `validity` and `quality` of your question, you can correct for the quality and common method variance easily.
Load the package as:
```{r}
# devtools::install_github("sociometricresearch/cosme")
library(cosme)
```
## A simple example
`cosme` introduces the concept of a measurement error design, such as the `survey` package has a survey design object. You can define this measurement error design with three objects: your model design, your measurement error data and the data of the analysis. For a simple case, let's use the data from the European Social Survey already loaded with the package. The variables `trstplt`, `trstprl` and `trstprt` were asked with the same type of the question. In other words, they share a common method (for example, a likert type scale question). Sharing a common method allows us to correct for their common method variance. We could define the measurement error design object as this:
```{r}
# Data
data(ess7es)
ess_subset <- ess7es[1:3]
# This is the model definition
model_definition <- "
# Correct for measurement error
~~ trstplt + trstprl + trstprt
# Correct for common method variance
~ trstplt + trstprl + trstprt
"
# The measurement error data
me_data <-
data.frame(
question = c("trstprl", "trstplt", "trstprt"),
reliability = c(0.812, 0.852, 0.858),
validity = c(0.959, 0.965, 0.956),
quality = c(0.779, 0.822, 0.821)
)
# Define your measurement error design
me_obj <- medesign(model_definition, ess_subset, me_data)
me_obj
```
This object describes your measurement error design. With this, we simply pass it to `me_cmv_cor` to adjust the correlation of `trstplt`, `trstprl` and `trstprt` for common method variance as well as their measurement error:
```{r }
me_cmv_cor(me_obj)
```
## Another simple example
The previous example corrected only variables `trstplt`, `trstprl` and `trstprt`. What if we have more groups of variables that share a common method? Just keep adding them to the model syntax! For example, `stfedu` and `stfhlth` also share a common method, let's add them to the model syntax and make sure we have data on `me_data` for them:
```{r }
# Data
data(ess7es)
ess_subset <- ess7es[1:5]
# This is the model definition
model_definition <- "
# Correct for measurement error on all variables (.)
~~ .;
# Correct for common method variance on these group of variables
~ trstplt + trstprl + trstprt;
~ stfedu + stfhlth
"
# The measurement error data
me_data <-
data.frame(
question = c("trstprl", "trstplt", "trstprt", "stfedu", "stfhlth"),
reliability = c(0.812, 0.852, 0.858, 0.870, 0.871),
validity = c(0.959, 0.965, 0.956, 0.915, 0.893),
quality = c(0.779, 0.822, 0.821, 0.796, 0.779)
)
# Define your measurement error design
me_obj <- medesign(model_definition, ess_subset, me_data)
me_obj
```
Once you have your measurement error design, we simply pass it to `me_cmv_cor` to adjust the correlation for common method variance as well as their quality:
```{r }
me_cmv_cor(me_obj)
```
Alternatively, you can use `me_cmv_cov` to adjust a covariance matrix for common method variance as well as quality.