codemark 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edb0e35579c3fd7f5039a51ec781b72dc0fba90113440867585f217be7bd6fc3
4
- data.tar.gz: c273461cab44d2de8aa3bd90baa436a803c1ef8c8258b7ad2e3b4e50a978fdea
3
+ metadata.gz: f81110351ac6e1a764a8285af1c6457d3fe54a727b5e81994b27b7c3d7df1be2
4
+ data.tar.gz: aff6ee918a882ddee838c82bbbda4e35abc06343de85d2eb9af0fc62eba54b40
5
5
  SHA512:
6
- metadata.gz: 3782a33d4902fe93d98f9918907f03b0a9f82b962f0a9e0a3da1152f321c9c11a84ed3daccbec48bff4049b621a3be768737fd9db7d30e53a53286d00ed0b039
7
- data.tar.gz: 45cc3bdc0c9b59baaba9324f0c5f8363a387f5ed503da16b5b8af943c555630c98abc10e0adb19e387ff62e3151e381f776993164b3fbb20f344a83f30f509f1
6
+ metadata.gz: 22a2bec40ada1ff1eb87eaa11fbeb140429506922eb47b4644859250f43823fd98120f0ba287b3dbddecbb2949301ff61c0c2ca30842d57d620adc567fce11c1
7
+ data.tar.gz: 1530d77f04fffa17869d5cf911d3bb666433a83baaaa6a80f6869e25c5faf9f2dd0fc7716273ae360fc0feb1eb521d64d0031913d2f57448ef7edb4f28094e83
data/README.md CHANGED
@@ -24,7 +24,23 @@ CodeMark will produce a corresponding file called `filename.R`
24
24
 
25
25
  ## Testing
26
26
 
27
- Not yet implemented
27
+ There is only one test currently, and it ensures that fixtures are processed accurately (i.e., a given Rmd file is correctly converted into a given R file).
28
+
29
+ ```shell
30
+ rake spec
31
+ ```
32
+
33
+ If the R file is accurately produced, `minitest` helpfully shows line diffs between the fixture R file and the generated R script.
34
+
35
+ If you deliberately change the behavior of CodeMark so that it produces different R output, then you must update the R script fixture:
36
+
37
+ ```shell
38
+ rake install # builds and reinstalls codemark gem locally
39
+ cd spec/fixtures
40
+ codemark sem-intro.Rmd
41
+ ```
42
+
43
+
28
44
 
29
45
  ## Contribute
30
46
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ task :default => :spec
2
2
 
3
3
  desc 'Run specs'
4
4
  task :spec do
5
- sh 'ruby -I lib spec/citesight_spec.rb'
5
+ sh 'ruby -I lib spec/codemark_spec.rb'
6
6
  end
7
7
 
8
8
  desc 'Rerun specs'
@@ -33,7 +33,11 @@ module CodeMark
33
33
  # end
34
34
 
35
35
  def header(text, header_level)
36
- "#" + "*"*header_level + " " + text + "\n\n"
36
+ if (@code_started and !@code_ignore)
37
+ "# " + text + "\n"
38
+ else
39
+ "#" + "*"*header_level + " " + text + "\n\n"
40
+ end
37
41
  end
38
42
 
39
43
  def hrule()
@@ -1,4 +1,4 @@
1
1
  module CodeMark
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  DATE = '2021-05-08'
4
4
  end
@@ -1,3 +1,72 @@
1
+ #* Introduction to R
2
+
3
+ # The best way to learn R from scratch is by installing and running the
4
+ # [Swirl](https://swirlstats.com/students.html) tutorials in RStudio. Here, we
5
+ # review the most basic essentials to R.
6
+
7
+ # Variables: R allows you to store data, values, and results of your analyses
8
+ # in variables. Here is an example of how to assign values to variables:
9
+
10
+ value <- 5
11
+ construct_name <- "PO"
12
+
13
+ # Collections: Multiple values can be defined and stored together. Vectors are
14
+ # collections of simple values (numbers, characters). Lists are collections of
15
+ # simple values or even other collections
16
+
17
+
18
+
19
+ # Vector of five numbers
20
+ numbers <- c(1, 2, 3, 4, 5)
21
+
22
+ # Vector of characters (letters or numbers in quotes)
23
+ construct_names <- c("PO", "PI")
24
+
25
+ # List of values and vectors
26
+ construct_definition <- list(
27
+ name = "Purchase Intention",
28
+ items = c("pi_1", "pi_2", "pi_3", "pi_4"))
29
+
30
+ # We can then extract what we have stored in these collections as we need them.
31
+
32
+ construct_names[2]
33
+
34
+ construct_definition$items
35
+
36
+ # Operations: Simple mathematical operations can be computed on values
37
+ # (numbers, words, etc.) or on variables. R is specially suited to performing
38
+ # operations on vectors (like our `numbers` from above).
39
+
40
+ 5 * 2
41
+
42
+ numbers <- 1:5
43
+
44
+ numbers^2
45
+
46
+ # Functions: Complex operations that require more information to compute are
47
+ # often packaged as functions. These function takes arguments and return results
48
+ # that can be stored in variables or displayed on screen. Note that comments
49
+ # (descriptive text that does not run) is prefixed with a pound sign ("#").
50
+
51
+
52
+
53
+ # load data from a file into a variable using the "read.csv" function
54
+ influence_data <- read.csv("data/influencer_data_book_final.csv")
55
+
56
+ # run a regression analysis
57
+ influence_regr <- lm(formula = pi_1 ~ pq_1 + sic_1, data = influence_data)
58
+
59
+ # show a summary of results from the regression on screen
60
+ summary(influence_regr)
61
+
62
+ # save the summary to a variable for further inspection
63
+ regr_report <- summary(influence_regr)
64
+
65
+ # Variables, like the regression report we are storing in `regr_report`, often
66
+ # contain a deeper structure of values that one can inspect:
67
+
68
+ regr_report$r.squared
69
+
1
70
  #* Introduction SEM
2
71
 
3
72
  # Structural Equation Modeling excels at allowing researchers to measure
@@ -29,10 +98,6 @@ influence_mm <- constructs(
29
98
 
30
99
  #* Structural Model
31
100
 
32
- # We can define the structural model of an SEM by specifying the
33
- # *relationships* between the constructs — specifically, the causal paths *from*
34
- # each construct *to* other constructs.
35
-
36
101
  influence_sm <- relationships(
37
102
  paths(from = c("PL", "PQ"), to = c("PI")))
38
103
 
@@ -78,12 +143,6 @@ influence_summary <- summary(influence_model)
78
143
 
79
144
  influence_summary$quality$fit
80
145
 
81
- influence_summary$quality$fit$curated$ordinary
82
-
83
- # These fit metrics should be familiar to CB-SEM practitioners. The summary
84
- # object can also be inspect for the estimated parameters of interest, such as
85
- # the measurement quality:
86
-
87
146
  influence_summary$quality$reliability
88
147
 
89
148
  # And also the structural paths that researchers often hypothesize
@@ -95,6 +154,8 @@ influence_summary$paths
95
154
  # Researchers often find that it is helpful to get a high-level glimpse of
96
155
  # their model description and results from a visualization.
97
156
 
157
+ plot(influence_model)
158
+
98
159
  #* Join us
99
160
 
100
161
  #** Collaboration and Feedback
@@ -6,13 +6,79 @@ output: pdf_document
6
6
  always_allow_html: true
7
7
  ---
8
8
 
9
+ # Introduction to R
10
+
11
+ The best way to learn R from scratch is by installing and running the [Swirl](https://swirlstats.com/students.html) tutorials in RStudio. Here, we review the most basic essentials to R.
12
+
13
+ Variables: R allows you to store data, values, and results of your analyses in variables. Here is an example of how to assign values to variables:
14
+
15
+ ```{r}
16
+ value <- 5
17
+ construct_name <- "PO"
18
+ ```
19
+
20
+ Collections: Multiple values can be defined and stored together. Vectors are collections of simple values (numbers, characters). Lists are collections of simple values or even other collections
21
+
22
+ ```{r}
23
+ # Vector of five numbers
24
+ numbers <- c(1, 2, 3, 4, 5)
25
+
26
+ # Vector of characters (letters or numbers in quotes)
27
+ construct_names <- c("PO", "PI")
28
+
29
+ # List of values and vectors
30
+ construct_definition <- list(
31
+ name = "Purchase Intention",
32
+ items = c("pi_1", "pi_2", "pi_3", "pi_4"))
33
+ ```
34
+
35
+ We can then extract what we have stored in these collections as we need them.
36
+
37
+ ```{r}
38
+ construct_names[2]
39
+
40
+ construct_definition$items
41
+ ```
42
+
43
+ Operations: Simple mathematical operations can be computed on values (numbers, words, etc.) or on variables. R is specially suited to performing operations on vectors (like our `numbers` from above).
44
+
45
+ ```{r, }
46
+ 5 * 2
47
+
48
+ numbers <- 1:5
49
+
50
+ numbers^2
51
+ ```
52
+
53
+ Functions: Complex operations that require more information to compute are often packaged as functions. These function takes arguments and return results that can be stored in variables or displayed on screen. Note that comments (descriptive text that does not run) is prefixed with a pound sign ("#").
54
+
55
+ ```{r}
56
+ # load data from a file into a variable using the "read.csv" function
57
+ influence_data <- read.csv("data/influencer_data_book_final.csv")
58
+
59
+ # run a regression analysis
60
+ influence_regr <- lm(formula = pi_1 ~ pq_1 + sic_1, data = influence_data)
61
+
62
+ # show a summary of results from the regression on screen
63
+ summary(influence_regr)
64
+
65
+ # save the summary to a variable for further inspection
66
+ regr_report <- summary(influence_regr)
67
+ ```
68
+
69
+ Variables, like the regression report we are storing in `regr_report`, often contain a deeper structure of values that one can inspect:
70
+
71
+ ```{r}
72
+ regr_report$r.squared
73
+ ```
74
+
9
75
  # Introduction SEM
10
76
 
11
77
  Structural Equation Modeling excels at allowing researchers to measure relationships between multi-item constructs. *Constructs* are statistical representation of concepts that are hard to measure in with a singular metric, and are best represented by multiple measurements.
12
78
 
13
79
  Each SEM is defined by two models: a **measurement model** that describes how each construct is measured using multiple items, and **structural model** that describes the structure of causal relationships between the constructs. The parameters of an SEM can then be **estimated** and **visualized** by the SEMinR package.
14
80
 
15
- ```{r eval=TRUE, echo=FALSE}
81
+ ```{r echo=FALSE, cache=TRUE}
16
82
  library(seminr)
17
83
 
18
84
  influence_mm <- constructs(
@@ -27,7 +93,6 @@ influence_model <- specify_model(influence_mm, influence_sm)
27
93
  influence_model_plot <- plot(influence_model)
28
94
  save_plot("figures/influencer_model_plot.png", influence_model_plot)
29
95
  ```
30
-
31
96
  ```{r simpleModel, fig.align = 'center', out.width = "50%", fig.cap = "Simplified Influencer Model", echo = F}
32
97
  knitr::include_graphics("figures/influencer_model_plot.png")
33
98
  ```
@@ -35,7 +100,6 @@ knitr::include_graphics("figures/influencer_model_plot.png")
35
100
  # Measurement Model
36
101
 
37
102
  We can define the measurement model of an SEM simply by describing each construct by its set of *measurement items* that *reflect* the underlying concept. Let's see a simplified example from the Influencer model and dataset we will use:
38
-
39
103
  ```{r}
40
104
  library(seminr)
41
105
 
@@ -50,7 +114,6 @@ Four constructs are defined in this measurement model. Note how the constructs a
50
114
  # Structural Model
51
115
 
52
116
  We can define the structural model of an SEM by specifying the *relationships* between the constructs — specifically, the causal paths *from* each construct *to* other constructs.
53
-
54
117
  ```{r}
55
118
  influence_sm <- relationships(
56
119
  paths(from = c("PL", "PQ"), to = c("PI")))
@@ -91,7 +154,7 @@ The `influence_summary` object holds a wealth of other estimated values that res
91
154
  influence_summary$quality$fit
92
155
  ```
93
156
 
94
- ```{r eval=FALSE, echo=TRUE}
157
+ ```{r echo=FALSE}
95
158
  influence_summary$quality$fit$curated$ordinary
96
159
  ```
97
160
 
@@ -113,6 +176,10 @@ influence_summary$paths
113
176
 
114
177
  Researchers often find that it is helpful to get a high-level glimpse of their model description and results from a visualization.
115
178
 
179
+ ```{r eval=FALSE}
180
+ plot(influence_model)
181
+ ```
182
+
116
183
  ```{r echo=FALSE, results='hide', cache=TRUE}
117
184
  png(filename = "figures/influence_estimated_plot.png", width = 900, height=600)
118
185
  plot(influence_model)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codemark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soumya Ray