我正在尝试运行bestglm命令但收到错误消息
if(any(Column1Test))中的错误停止(" 1' s的列不能被使用!拦截始终包括在内。"):缺失值为TRUE / FALSE需要
以下是bestglm
函数的错误消息的源代码:
#Test if there is a column of 1's in X.
#Only do this test if:
#1) X contains at least one column corresponding to a quantitative variable
#2) IncludeInterceptQ (intercept is included already)
if (!all(FactorsQ)&& IncludeInterceptQ){
X2<-X[,!FactorsQ,drop=FALSE] #removing factor variables
p2<-ncol(X2)
Column1Test<-apply(X2-matrix(rep(1,n*p2),ncol=p2), MARGIN=2, function(x) 0==sum(abs(x)))
if (any(Column1Test))
stop("Column of 1's can't be used! Intercept always included.")
}
我的数据中没有一列1,我不知道这意味着什么。以下是我正在使用的代码。有人可以帮忙吗?
#Lables all variables in the data file
allVars<- c('Full_ID','cen','fam','id','group','groupControlPersistPreterm','excludePersis','sefosgroup','sefosexclude','Conners_Parent', 'age','sex','IQ','ga','bw','sib','DIVA_Parent_score','Reasons_for_exclusion_CPT','exclude', 'Persistent_remitted_parent','Previous_ADHD_Status1','inattention','hypimp','subtype','BFISparent','adhdinptBFIS','adhd_parent','exclude_nogo15','exclude_cnv15','exclude_go15','N2inc_latencyFz','N2inc_ampFz','N2cong_latencyFz','N2cong_ampFz','N2inc_latencyFCz','N2inc_ampFCz','N2cong_latencyFCz','N2cong_ampFCz','Pe_latencyCz','Pe_ampCz', 'Pe_latencyCPz','Pe_ampCPz','PNe_latencyFz','PNe_ampFz','PNe_latencyFCz','PNe_ampFCz','ERN_latencyFz','ERN_ampFz','ERN_latencyFCz','ERN_ampFCz','cnv','cuep3_amp','Gop3_amp','Nogo_p3_amp','cue_p3_lat','Gop3_lat','Nogo_p3_lat','excluded_cuep3','excluded_go','excluded_nogo','excluded_cnv','CPT_OE','CPT_MRT', 'CPT_RTV','CPT_FalseAlarm','CPT_OnotX','PersistRemitControl_CPT','PersistRemit_CPT','exclude_background','exclude_GA','alphalg1','alphalg2','betalg1','betalg2','thetalg1','thetalg2','deltalg1','deltalg2','nogop3_czlat','nogop3_czamp','nogop3_czlat_BC','nogop3_czamp_BC','nogop3_fczlat','nogop3_fczamp','nogop3_fczlat_BC', 'nogop3_fczamp_BC', 'nogon2_fzlat', 'nogon2_fzamp', 'nogon2_fzlat_BC','nogon2_fzamp_BC','gop3_pzlat','gop3_pzamp','gop3_pzlat_BC','gop3_pzamp_BC','gop3_cpzlat','gop3_cpzamp','gop3_cpzlat_BC','gop3_cpzamp_BC','CNVcz','CNVcz_BC','CNVcpz','CNVcpz_BC','cuep3_pzlat','cuep3_pzamp','cuep3_pzlat_BC','cuep3_pzamp_BC','excludeGOseg','excludeNOGOseg','excludeCUEseg','segcue','segCNV','seggo','segnogo','CNV','excludeIQ','excludeGA','excludeADHDga','excludePTga','excludeCTga','excludeADHDrating','N2cong_latency_BC_Fz','N2cong_amp_BC_Fz','N2cong_latency_BC_FCz','N2cong_amp_BC_FCz','N2incong_latency_BC_Fz','N2incong_amp_BC_Fz','N2incong_latency_BC_FCz','N2incong_amp_BC_FCz', 'ERN_latency_BC_Fz','ERN_amp_BC_Fz', 'ERN_latency_BC_FCz','ERN_amp_BC_FCz','PNe_latency_BC_Fz','PNe_amp_BC_Fz','PNe_latency_BC_FCz','PNe_amp_BC_FCz','Pe_latency_BC_Cz','Pe_amp_BC_Cz','Pe_latency_BC_CPz','Pe_amp_BC_CPz','spin3_fam','spin3_sample','spin3_allgroups','spin3_preterm','spin3_gestationalage','spin3_ft_bcp3_pz_base','spin3_ft_bcp3_pz_fast','spin3_ft_cnv_cz_base','spin3_ft_cnv_cz_fast','spin3_ft_mrt_base','spin3_ft_mrt_fast','spin3_ft_rtv_base','spin3_ft_rtv_fast','CNSLS5yrs','CNSLS1mnth')
# Read data from CSV file, with '.' as missing values
EL <- read.csv ('EL analysis_Aug 2017_ADHD_exclusion applied.csv', header=T, na.strings=".", col.names=allVars)
## Prepare data by setting those variables to NULL that are not required in the analysis
ELdata <- within(EL, {
Full_ID <- NULL # Delete
cen <- NULL
fam <- NULL
id <- NULL
groupControlPersistPreterm <- NULL
excludePersis <- NULL
sefosgroup <- NULL
sefosexclude <- NULL
sib <- NULL
DIVA_Parent_score <- NULL
Reasons_for_exclusion_CPT <- NULL
exclude <- NULL
Persistent_remitted_parent <- NULL
Previous_ADHD_Status1 <- NULL
inattention <- NULL
hypimp <- NULL
subtype <- NULL
BFISparent <- NULL
adhdinptBFIS <- NULL
adhd_parent <- NULL
exclude_nogo15 <- NULL
exclude_cnv15 <- NULL
exclude_go15 <- NULL
cnv <- NULL
excluded_cuep3 <- NULL
excluded_go <- NULL
excluded_nogo <- NULL
excluded_cnv <- NULL
PersistRemitControl_CPT <- NULL
PersistRemit_CPT <- NULL
exclude_background <- NULL
exclude_GA <- NULL
excludeCUEseg <- NULL
segcue <- NULL
segCNV <- NULL
seggo <- NULL
segnogo <- NULL
CNV <- NULL
excludeIQ <- NULL
excludeGA <- NULL
excludeADHDga <- NULL
excludePTga <- NULL
excludeCTga <- NULL
excludeADHDrating <- NULL
spin3_fam <- NULL
spin3_sample <- NULL
spin3_allgroups <- NULL
spin3_preterm <- NULL
spin3_gestationalage <- NULL
y <- CNSLS5yrs #EL variable is DV
})
## Reorder variables
ELdata <-ELdata[,c('Conners_Parent','age','sex','group','IQ','ga','bw','N2inc_latencyFz','N2inc_ampFz','N2cong_latencyFz','N2cong_ampFz','N2inc_latencyFCz','N2inc_ampFCz','N2cong_latencyFCz','N2cong_ampFCz','Pe_latencyCz','Pe_ampCz','Pe_latencyCPz','Pe_ampCPz','PNe_latencyFz','PNe_ampFz','PNe_latencyFCz','PNe_ampFCz','ERN_latencyFz','ERN_ampFz','ERN_latencyFCz','ERN_ampFCz','cuep3_amp','Gop3_amp','Nogo_p3_amp','cue_p3_lat','Gop3_lat','Nogo_p3_lat','CPT_OE','CPT_MRT','CPT_RTV','CPT_FalseAlarm','CPT_OnotX','alphalg1','alphalg2','betalg1','betalg2','thetalg1','thetalg2','deltalg1','deltalg2','nogop3_czlat','nogop3_czamp','nogop3_czlat_BC','nogop3_czamp_BC','nogop3_fczlat','nogop3_fczamp','nogop3_fczlat_BC','nogop3_fczamp_BC','nogon2_fzlat','nogon2_fzamp','nogon2_fzlat_BC','nogon2_fzamp_BC','gop3_pzlat','gop3_pzamp','gop3_pzlat_BC','gop3_pzamp_BC','gop3_cpzlat','gop3_cpzamp','gop3_cpzlat_BC','gop3_cpzamp_BC','CNVcz','CNVcz_BC','CNVcpz','CNVcpz_BC','cuep3_pzlat','cuep3_pzamp','cuep3_pzlat_BC','cuep3_pzamp_BC','N2cong_latency_BC_Fz','N2cong_amp_BC_Fz','N2cong_latency_BC_FCz','N2cong_amp_BC_FCz','N2incong_latency_BC_Fz','N2incong_amp_BC_Fz','N2incong_latency_BC_FCz','N2incong_amp_BC_FCz','ERN_latency_BC_Fz','ERN_amp_BC_Fz','ERN_latency_BC_FCz','ERN_amp_BC_FCz','PNe_latency_BC_Fz','PNe_amp_BC_Fz','PNe_latency_BC_FCz','PNe_amp_BC_FCz','Pe_latency_BC_Cz','Pe_amp_BC_Cz','Pe_latency_BC_CPz','Pe_amp_BC_CPz','spin3_ft_bcp3_pz_base','spin3_ft_bcp3_pz_fast','spin3_ft_cnv_cz_base','spin3_ft_cnv_cz_fast','spin3_ft_mrt_base','spin3_ft_mrt_fast','spin3_ft_rtv_base','spin3_ft_rtv_fast','CNSLS1mnth','y')]
dim(ELdata)
describe(ELdata)
res.EL <-
bestglm(ELdata)
res.EL$BestModels
答案 0 :(得分:1)
我遇到了同样的错误,它是通过删除bestglm命令中包含的那些变量中的NA来解决的。您可以从原始数据框DF中删除NA,如下所示:
df <- DF[is.na(DF$foo)==F & is.na(DF$bar)==F,]
如果在上面的方括号中添加那些具有NA的列,则可以在新数据框df上运行bestglm