Beruflich Dokumente
Kultur Dokumente
alpha
Home
Blog
All packages
Search R packages
Search
<- Back to Bridging the Gap Between Qualitative Data and Quantitative Analysis
Usage
1
2
3
4
5
6
7
Arguments
text.var
grouping.var
The grouping variables. Default NULL generates one word list for all text. Also takes a single grouping
pdfcrowd.com
constrain
logical. If TRUE polarity values are constrained to be between -1 and 1 using the following
transformation:
((1 - (1/(1 + exp(polarity)))) * 2) - 1
negators
amplifiers
A character vector of terms that increase the intensity of a positive or negative word.
deamplifiers
A character vector of terms that decrease the intensity of a positive or negative word.
question.weight The weighting of questions (values from 0 to 1). Default 0 corresponds with the belief that questions
(pure questions) are not polarized. A weight may be applied based on the evidence that the
questions function with polarity.
amplifier.weight The weight to apply to amplifiers/deamplifiers (values from 0 to 1). This value will multiply the
The number of words to consider as valence shifters before the polarized word.
n.after
The number of words to consider as valence shifters after the polarized word.
rm.incomplete
logical. If TRUE text rows ending with qdap's incomplete sentence end mark ( | ) will be removed
from the analysis.
digits
...
pdfcrowd.com
Details
The equation used by the algorithm to assign value to polarity of each sentence fist utilizes the sentiment dictionary (Hu
and Liu, 2004) to tag polarized words. A context cluster (x_i^T) of words is pulled from around this polarized word (default
4 words before and two words after) to be considered as valence shifters. The words in this context cluster are tagged as
neutral (x_i^0), negator (x_i^N), amplifier (x_i^a), or de-amplifier (x_i^d). Neutral words hold no value in the equation but do
affect word count (n). Each polarized word is then weighted w based on the weights from the polarity.frame argument
and then further weighted by the number and position of the valence shifters directly surrounding the positive or
negative word. The researcher may provide a weight c to be utilized with amplifiers/de-amplifiers (default is .8; deamplifier
weight is constrained to -1 lower bound). Last, these context cluster (x_i^T) are summed and divided by the square root of
the word count (n) yielding an unbounded polarity score (C). Note that context clusters containing a comma before the
polarized word will only consider words found after the comma.
C=x_i^2/(n)
Where:
x_i^T=((1 + c * (x_i^A - x_i^D)) * w(-1)^(x_i^N))
x_i^A=(w_neg * x_i^a)
x_i^D = max(x_i^D', -1)
x_i^D'=(- w_neg * x_i^a + x_i^d)
w_neg= (x_i^N) mod 2
Value
Returns a list of:
open in browser PRO version
pdfcrowd.com
all
Note
open in browser PRO version
pdfcrowd.com
The polarity score is dependent upon the polarity dictionary used. This function defaults to the word polarity dictionary
used by Hu, M., & Liu, B. (2004), however, this may not be appropriate for the context of children in a classroom. The user
may (is encouraged) to provide/augment the dictionary (see the sentiment_frame function). For instance the word
"sick" in a high school setting may mean that something is good, whereas "sick" used by a typical adult indicates
something is not right or negative connotation (deixis).
Also note that polarity assumes you've run sentSplit .
References
Hu, M., & Liu, B. (2004). Mining opinion features in customer reviews. National Conference on Artificial Intelligence.
http://www.slideshare.net/jeffreybreen/r-by-example-mining-twitter-for
http://hedonometer.org/papers.html Links to papers on hedonometrics
See Also
https://github.com/trestletech/Sermon-Sentiment-Analysis
Examples
1
2
3
4
5
6
7
8
## Not run:
with(DATA, polarity(state, list(sex, adult)))
(poldat <- with(sentSplit(DATA, 4), polarity(state, person)))
counts(poldat)
scores(poldat)
plot(poldat)
poldat2 <- with(mraja1spl, polarity(dialogue,
pdfcrowd.com
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
pdfcrowd.com
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
pdfcrowd.com
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
pdfcrowd.com
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
library(gridBase)
library(qdap)
library(reports)
library(igraph)
library(plotrix)
library(gridExtra)
deb2dat <- subset(pres_debates2012, time=="time 2")
deb2dat[, "person"] <- factor(deb2dat[, "person"])
(deb2 <- with(deb2dat, polarity(dialogue, person)))
## Set up the network version
bg_black <- Animate(deb2, neutral="white", current.speaker.color="grey70")
bgb <- vertex_apply(bg_black, label.color="grey80", size=30, label.size=22,
color="grey40")
bgb <- edge_apply(bgb, label.color="yellow")
## Set up the bar version
deb2_bar <- Animate(deb2, as.network=FALSE)
## Generate a folder
loc2 <- folder(animation_polarity2)
## Set up the plotting function
oopt <- animation::ani.options(interval = 0.1)
pdfcrowd.com
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
Legend.cex <- 1
lapply(theseq, function(i) {
if (follow) {
png(file=sprintf("%s/images/Rplot%s.png", loc2, i),
width=650, height=725)
}
## Set up the layout
layout(matrix(c(rep(1, 9), rep(2, 4)), 13, 1, byrow = TRUE))
## Plot 1
par(mar=c(2, 0, 2, 0), bg="black")
#par(mar=c(2, 0, 2, 0))
set.seed(20)
plot.igraph(bgb[[i]], edge.curved=TRUE)
mtext(Title, side=3, col="white")
color.legend(Legend[1], Legend[2], Legend[3], Legend[4],
c("Negative", "Neutral", "Positive"), attributes(bgb)[["legend"]],
cex = Legend.cex, col="white")
## Plot2
plot.new()
vps <- baseViewports()
uns <- unit(c(-1.3,.5,-.75,.25), "cm")
p <- deb2_bar[[i]] +
theme(plot.margin = uns,
text=element_text(color="white"),
plot.background = element_rect(fill = "black",
color="black"))
print(p,vp = vpStack(vps$figure,vps$plot))
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
animation::ani.pause()
if (follow) {
dev.off()
}
})
}
FUN2()
## Detect OS
type <- if(.Platform$OS.type == "windows") shell else system
saveHTML(FUN2(), autoplay = FALSE, loop = TRUE, verbose = FALSE,
ani.height = 1000, ani.width=650,
outdir = loc2, single.opts =
"'controls': ['first', 'play', 'loop', 'speed'], 'delayMin': 0")
FUN2(TRUE)
#=====================#
library(animation)
library(grid)
library(gridBase)
library(qdap)
library(reports)
library(igraph)
library(plotrix)
library(gplots)
pdfcrowd.com
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
pdfcrowd.com
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
open in browser PRO version
width=650, height=725)
}
## Set up the layout
layout(matrix(c(rep(1, 9), rep(2, 4)), 13, 1, byrow = TRUE))
## Plot 1
par(mar=c(2, 0, 2, 0), bg="black")
#par(mar=c(2, 0, 2, 0))
set.seed(20)
plot.igraph(bgb[[i]], edge.curved=TRUE)
mtext(Title, side=3, col="white")
color.legend(Legend[1], Legend[2], Legend[3], Legend[4],
c("Negative", "Neutral", "Positive"), attributes(bgb)[["legend"]],
cex = Legend.cex, col="white")
## Plot2
plot.new()
vps <- baseViewports()
uns <- unit(c(-1.3,.5,-.75,.25), "cm")
p <- deb2_bar[[i]] +
theme(plot.margin = uns,
text=element_text(color="white"),
plot.background = element_rect(fill = "black",
color="black"))
print(p,vp = vpStack(vps$figure,vps$plot))
animation::ani.pause()
if (follow) {
dev.off()
}
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
})
}
FUN2()
## Detect OS
type <- if(.Platform$OS.type == "windows") shell else system
saveHTML(FUN2(), autoplay = FALSE, loop = TRUE, verbose = FALSE,
ani.height = 1000, ani.width=650,
outdir = loc2b, single.opts =
"'controls': ['first', 'play', 'loop', 'speed'], 'delayMin': 0")
FUN2(TRUE)
## Increased complexity
## -------------------## Helper function to cbind ggplots
cbinder <- function(x, y){
uns_x <- unit(c(-1.3,.15,-.75,.25), "cm")
uns_y <- unit(c(-1.3,.5,-.75,.15), "cm")
x <- x + theme(plot.margin = uns_x,
text=element_text(color="white"),
plot.background = element_rect(fill = "black",
color="black")
)
pdfcrowd.com
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
pdfcrowd.com
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
## Plot 1
par(mar=c(2, 0, 2, 0), bg="black")
#par(mar=c(2, 0, 2, 0))
set.seed(20)
plot.igraph(bgb[[i]], edge.curved=TRUE)
mtext(Title, side=3, col="white")
color.legend(Legend[1], Legend[2], Legend[3], Legend[4],
c("Negative", "Neutral", "Positive"), attributes(bgb)[["legend"]],
cex = Legend.cex, col="white")
## Plot2
plot.new()
vps <- baseViewports()
p <- deb2_combo[[i]]
print(p,vp = vpStack(vps$figure,vps$plot))
animation::ani.pause()
if (follow) {
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
dev.off()
}
})
}
FUN3()
type <- if(.Platform$OS.type == "windows") shell else system
saveHTML(FUN3(), autoplay = FALSE, loop = TRUE, verbose = FALSE,
ani.height = 1000, ani.width=650,
outdir = loc3, single.opts =
"'controls': ['first', 'play', 'loop', 'speed'], 'delayMin': 0")
FUN3(TRUE)
##-----------------------------##
## Constraining between -1 & 1 ##
##-----------------------------##
## The old behavior of polarity constrained the output to be between -1 and 1
## this can be replicated via the `constrain = TRUE` argument:
polarity("really hate anger")
polarity("really hate anger", constrain=TRUE)
#==================#
## Static Network ##
#==================#
(poldat <- with(sentSplit(DATA, 4), polarity(state, person)))
m <- Network(poldat)
m
pdfcrowd.com
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
pdfcrowd.com
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
mraja1spl: Romeo and Juliet: Act 1 Dialogue Merged with Demographics and...
multicsv: Read/Write Multiple csv Files at a Time
multigsub: Multiple gsub
multiscale: Nested Standardization
name2sex: Names to Gender
new_project: Project Template
ngrams: Generate ngrams
object_pronoun_type: Count Object Pronouns Per Grouping Variable
outlier_detect: Detect Outliers in Text
outlier_labeler: Locate Outliers in Numeric String
paste2: Paste an Unspecified Number Of Text Columns
phrase_net: Phrase Nets
plot.Network: Plots a Network Object
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
pdfcrowd.com
syllabication: Syllabication
synonyms: Search For Synonyms
t.DocumentTermMatrix: Transposes a DocumentTermMatrix object
t.TermDocumentMatrix: Transposes a TermDocumentMatrix object
termco: Search For and Count Terms
termco_c: Combine Columns from a termco Object
tot_plot: Visualize Word Length by Turn of Talk
trans_cloud: Word Clouds by Grouping Variable
trans_context: Print Context Around Indices
trans_venn: Venn Diagram by Grouping Variable
type_token_ratio: Type-Token Ratio
unique_by: Find Unique Words by Grouping Variable
visual: Generic visual Method
open in browser PRO version
pdfcrowd.com
0 Comments
R Packages
pdfcrowd.com
Recommend
Share
Sort by Bes
WHAT'S THI
ALSO ON R PACKAGES
residuals to olmm?
pdfcrowd.com
Subscribe
Privacy
This site was developed by Ian Howson. I'm available to help with your software and statistics projects. All
documentation is copyright its authors; I didn't write any of that. Email me or Tweet to @ianphowson if you
have questions or problems.
pdfcrowd.com