在R中,我想测试偏最小二乘(PLS)模型m1与非嵌套替代m2的规范,应用Davidson-MacKinnon J检验。对于简单的线性结果Y,使用plsr估计器后跟jtest命令可以很好地工作:
# Libraries and data
library(plsr)
library(plsRglm)
library(lmtest)
Z <- Cornell # illustration dataset coming with the plsrglm package
# Simple linear model
m1 <- plsr(Z$Y ~ Z$X1 + Z$X2 + Z$X3 + Z$X4 + Z$X5 ,2) # including X1
m2 <- plsr(Z$Y ~ Z$X6 + Z$X2 + Z$X3 + Z$X4 + Z$X5 ,2) # including X6 as alternative
jtest(m1,m2)
但是,如果我使用广义线性模型(plsRglm)估计来解释结果的可能非线性分布,例如:
# Generalized Model
m1 <- plsRglm(Z$Y ~ Z$X1 + Z$X2 + Z$X3 + Z$X4 + Z$X5 ,2, modele = "pls-glm-family", family=Gamma(link = "log"), pvals.expli=TRUE)
m2 <- plsRglm(Z$Y ~ Z$X6 + Z$X2 + Z$X3 + Z$X4 + Z$X5 ,2, modele = "pls-glm-family", family=Gamma(link = "log"), pvals.expli=TRUE)
使用jtest时遇到错误:
> jtest(m1,m2)
Error in terms.default(formula1) : no terms component nor attribute
>
似乎plsRglm不保存类&#34;公式&#34;的对象,jtest可以处理。有人建议如何编辑我的代码以使其工作吗?
谢谢!