From 4ecf08a5f4ee347b2ee5b985618205ef07df2970 Mon Sep 17 00:00:00 2001 From: EeshanChatterjee Date: Tue, 7 Jan 2014 12:22:26 +0530 Subject: [PATCH 1/4] Update sentiment_analysis.R --- sentiment_analysis.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sentiment_analysis.R b/sentiment_analysis.R index fc33911..4503b1b 100644 --- a/sentiment_analysis.R +++ b/sentiment_analysis.R @@ -74,4 +74,8 @@ confTable <- table(predict(classifier, results), results[,6], dnn=list('predicte confTable #run a binomial test for confidence interval of results -binom.test(confTable[1,1] + confTable[2,2], nrow(results), p=0.5) \ No newline at end of file +binom.test(confTable[1,1] + confTable[2,2], nrow(results), p=0.5) + +# chi sqr polarity test of the confusion table + +# PMI-based polarity test for confTable From 423ee2f05df91087d2fc7310788f88201857bfa4 Mon Sep 17 00:00:00 2001 From: EeshanChatterjee Date: Tue, 7 Jan 2014 12:27:36 +0530 Subject: [PATCH 2/4] added polarity funcs --- polarityFuncs.R | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 polarityFuncs.R diff --git a/polarityFuncs.R b/polarityFuncs.R new file mode 100644 index 0000000..54a419b --- /dev/null +++ b/polarityFuncs.R @@ -0,0 +1,113 @@ +# ======================================================================================# +# This Script contains functions designed to return a +# numerical value indicating the strength of polarity, or the polatiry value +# of a word or phrase. + +# The input taken by the functions are in the form of 2x2 Contingency matrix, eg. +# pos neg +# c | f(c,pos) f(c,neg) +# ~c | f(~c,pos) f(~c,neg) +# ======================================================================================# + + +# ================================================================================ +# Function: calcChiSqrPV +# Task: Calculate the Chi Square based Polarity Value from a contingency matrix +# Input: Numeric vector/Matrix representing the contingeny matrix +# Output: Polarity Value +# ================================================================================ + +calcChiSqrPV<-function(conMat){ + + # Chi Square based polarity value + mat<- matrix(as.numeric(conMat), ncol=2, byrow=TRUE) + expmat<- matrix(data=NA, nrow=2, ncol=2) + + # Sum of all elements of contingency matrix + sum<-0 + + #Loop to get the sum + for(i in 1:2){ # row + for(j in 1:2){ #coloumn + sum<-sum+mat[i,j] + } + } + + # For-loop to genetare matrix of expected values + for(i in 1:2){ # row + for(j in 1:2){ #coloumn + rowsum<-0 + colsum<-0 + + for(k in 1:2){ + rowsum<- rowsum+mat[i,k] + } + + for(k in 1:2){ + colsum<- colsum+mat[k,j] + } + + expmat[i,j]<- (rowsum*colsum)/sum + } + } + + chisqr<-0 + + # Loop to calculate the chi-square value + for(i in 1:2){ # row + for(j in 1:2){ #coloumn + + chisqr<- chisqr+ ((mat[i,j]-expmat[i,j])^2)/expmat[i,j] + + } + } + + Pc_pos<-mat[1,1]/(mat[1,1]+mat[2,1]) + Pc_neg<-mat[1,2]/(mat[1,2]+mat[2,2]) + + if(Pc_pos Date: Tue, 7 Jan 2014 12:31:22 +0530 Subject: [PATCH 3/4] Update sentiment_analysis.R calling the polarity functions --- sentiment_analysis.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sentiment_analysis.R b/sentiment_analysis.R index 4503b1b..3f673b8 100644 --- a/sentiment_analysis.R +++ b/sentiment_analysis.R @@ -76,6 +76,11 @@ confTable #run a binomial test for confidence interval of results binom.test(confTable[1,1] + confTable[2,2], nrow(results), p=0.5) -# chi sqr polarity test of the confusion table +source("polarityFuncs.R") +# chi sqr polarity test of the confusion table +chiSqrPV = calcChiSqrPV(as.vector(confTable)) +chiSqrPV # PMI-based polarity test for confTable +PmiPV = calcPmiPV(as.vector(confTable)) +PmiPV From 14f8d5496716a99266d5678322b330d4524a8909 Mon Sep 17 00:00:00 2001 From: EeshanChatterjee Date: Tue, 7 Jan 2014 12:32:02 +0530 Subject: [PATCH 4/4] Update sentiment_analysis.R --- sentiment_analysis.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentiment_analysis.R b/sentiment_analysis.R index 3f673b8..5d8347d 100644 --- a/sentiment_analysis.R +++ b/sentiment_analysis.R @@ -76,7 +76,7 @@ confTable #run a binomial test for confidence interval of results binom.test(confTable[1,1] + confTable[2,2], nrow(results), p=0.5) -source("polarityFuncs.R") +source("~/Documents/GitHub/polarityFuncs.R") # chi sqr polarity test of the confusion table chiSqrPV = calcChiSqrPV(as.vector(confTable))