首页 > 解决方案 > 用固定斜率或截距估计 R 中的线性模型

问题描述

我想估计具有固定截距(模型 a)斜率(模型 b)的模型,并估计无约束模型(c),其中每个参数都允许变化,以及空模型(d) ,没有人可以。然后,我想使用 BIC/AIC 值的对数似然比检验来比较它们(我不知道哪个更好)。

这是我的代码,但我不知道它是否合适。另请注意,我在这里只考虑 1 个主题,但是如何将这个模型比较整合到几个主题?


我有几个条件的反应时间,我将这些条件转换为分位数,然后我使用遗嘱认证和倒数比例“标准化”它们。

library(pracma)
library(lmtest)
library(ggplot2)
library(scales)

rt1 <- c(2343, 1411, 928, 767, 929, 775, 1008, 922, 1127, 1516, 904, 771, 1044, 974, 1096, 1688, 2018, 1726, 1523, 1910, 1186, 1287, 1220, 834, 1267,1827, 859, 835, 1729, 859, 1305, 1238, 1451, 756, 1331, 872, 729, 1053, 789, 982, 737, 1410, 865, 926, 885, 1026, 657, 1528, 1046, 930, 770, 936, 1019, 1156, 964, 1951, 783, 769, 1693, 775, 688, 913)

rt2 <- c(1143, 752, 1071, 1215, 698, 803, 751, 869, 679, 801, 830, 935, 794, 676, 960, 857, 873, 658, 918, 769, 649, 676, 829, 803, 672, 647, 756, 719, 558, 654, 854, 707, 676, 795, 632, 666, 764, 685, 699, 534, 547, 721, 837, 778, 608, 532, 564, 686, 830, 850, 577, 591, 630, 612, 728, 540, 785, 622, 538, 635, 606, 1083)

## Quantiles
qq1    = quantile(rt1,pp)
qq2    = quantile(rt2,pp)

qq1inv    = -1/qq1*1000
qq2inv    = -1/qq2*1000

## Probit scale
pp = c(1,2,3,5,6,seq(10,90,5),95,96,97,98,99)/100


## Create dataframe
inv_qquantile <- c(qq1inv,qq2inv)
pp_scale <- rep(pp,length.out=length(qquantile))
conditions <- c(rep('cond1',length.out=length(qq1inv)),rep('cond2',length.out=length(qq2inv))

dataall=data.frame(condition,inv_qquantile,pp_scale)

ggplot(dataall, aes(inv_qquantile,pp_scale,color=condition)) +
  geom_point() +
  scale_y_continuous(trans = probit_trans())+
  geom_smooth(method = lm,se=F)

我有我的 4 个模型:

## Estimate models

#-- slope fixed
a = glm(pp_scale ~ 0+inv_qquantile+condition,family = binomial(link = "probit"), dataall)

#-- intercept fixed
b = glm(pp_scale ~ inv_qquantile:condition,family = binomial(link = "probit"), dataall)

#-- unconstrained model
c = glm(pp_scale ~ inv_qquantile*condition,family = binomial(link = "probit"), dataall)

#-- null model
d = glm(pp_scale ~ 1,family = binomial(link = "probit"), dataall)

BIC(a)
BIC(b)
BIC(c)
BIC(d)

标签: roptimizationlog-likelihood

解决方案


推荐阅读