如何测试两个提升值是否显着不同?

How to test if two lift values are significantly different from each other?

考虑这段代码:

# Load libraries
library(RCurl)
library(TraMineR)
library(PST)

# Get data
x <- getURL("https://gist.githubusercontent.com/aronlindberg/08228977353bf6dc2edb3ec121f54a29/raw/c2539d06771317c5f4c8d3a2052a73fc485a09c6/challenge_level.csv")
data <- read.csv(text = x)

# Load and transform data
data <- read.table("thread_level.csv", sep = ",", header = F, stringsAsFactors = F)

# Create sequence object
data.seq <- seqdef(data[2:nrow(data),2:ncol(data)], missing = NA, right= NA, nr = "*")

# Make a tree
S1 <- pstree(data.seq, ymin = 0.05, L = 6, lik = FALSE, with.missing = TRUE)

# Look at contexts
cmine(S1, pmin = 0, state = "N3", l = 3)

然后我可以通过以下方式计算两个特定 "association rules" 提升值的显着性阈值:

# Calculate lift threshold for N2-QU->N3
ngood_idea <- sum(data.seq == "N3")
nn <- nrow(data.seq)*ncol(data.seq)
p_good_idea <- ngood_idea/nn

x <- seqdef("N2-QU")
p_context <- predict(S1, x, decomp = F, output = "prob")
p_not_context_good_idea <- (1-p_context)*(1-(p_good_idea))
p_context_good_idea <- p_context*p_good_idea
N2_QU_N3_threshold <- 1+1.645*sqrt(((1/nn)*(p_not_context_good_idea/p_context_good_idea)))

# Calculate lift threshold for N2-QU->N1
nbad_idea <- sum(data.seq == "N1")
nn <- nrow(data.seq)*ncol(data.seq)
p_bad_idea <- nbad_idea/nn

p_not_context_bad_idea <- (1-p_context)*(1-(p_bad_idea))
p_context_bad_idea <- p_context*p_bad_idea
N2_QU_N1_threshold <- 1+1.645*sqrt(((1/nn)*(p_not_context_bad_idea/p_context_bad_idea)))

# Print lift thresholds
N2_QU_N3_threshold
N2_QU_N1_threshold

但是,如果我想将两个提升值相互比较,看看它们之间是否有显着差异(类似于我可以将两个回归系数相互比较以查看它们是否存在显着差异的方式)彼此显着不同)?我怎样才能做到这一点?

利用这个等式:

$Z = \frac{\beta_1-\beta_2}{\sqrt{(SE\beta_1)^2+(SE\beta_2)^2}}$

其中$SE\beta$$\beta$的标准误差。

此等式由 Clogg 等人 (1995) 提供

来源:https://stats.stackexchange.com/questions/93540/testing-equality-of-coefficients-from-two-different-regressions

我们可以类推,以lifts为系数,根据Lenca et al (2008, p. 619)计算每个lift的方差

# Calculate conditional probability for I3
cp_good <- query(S1, context = "N2-QU", output= "prob")@.Data[attr(query(S1, context = "N2-QU", output= "prob")@.Data, "dimnames")[[2]]=="I3"]
cp_good <- unlist(cp_good)

# Calculate conditional probability for I1
cp_bad <- query(S1, context = "N2-QU", output= "prob")@.Data[attr(query(S1, context = "N2-QU", output= "prob")@.Data, "dimnames")[[2]]=="I1"]
cp_bad <- unlist(cp_bad)

# Calculate lift for I3
ngood_idea <- sum(data.seq == "I3")
nn <- nrow(data.seq)*ncol(data.seq)
p_good_idea <- ngood_idea/nn

good_lift <- cp_good/p_good_idea

# Calculate lift for I1
nbad_idea <- sum(data.seq == "I1")
nn <- nrow(data.seq)*ncol(data.seq)
p_bad_idea <- nbad_idea/nn

bad_lift <- cp_bad/p_bad_idea

# Calculate z_diff
p_context <- predict(S1, x, decomp = F, output = "prob")

p_not_context_good_idea <- (1-p_context)*(1-(p_good_idea))
p_context_good_idea <- p_context*p_good_idea

p_not_context_bad_idea <- (1-p_context)*(1-(p_bad_idea))
p_context_bad_idea <- p_context*p_bad_idea

var_good_idea <- ((1/nn)*(p_not_context_good_idea/p_context_good_idea))
var_bad_idea <- ((1/nn)*(p_not_context_bad_idea/p_context_bad_idea))

z_diff <- (good_lift-bad_lift)/sqrt(var_good_idea+var_bad_idea)
z_diff

差值的 z 值为 0.2556881

参考资料

Clogg, C. C., Petkova, E., & Haritou, A. (1995)。比较模型间回归系数的统计方法。 美国社会学杂志, 100(5), 1261-1293.]

Lenca, P.、Meyer, P.、Vaillant, B. 和 Lallich, S. 2008。“关于为关联规则选择兴趣度量:面向用户的描述和多标准决策辅助”,欧洲运营杂志研究 (184:2),第 610–626 页 (doi: 10.1016/j.ejor.2006.10.059).