Lore
Lore

Reputation: 11

R: Error in bestglm - Error in if (any(Column1Test)) stop("Column of 1's can't be used! Intercept always included.")

I am trying to run the bestglm command but am getting the error message

Error in if (any(Column1Test)) stop("Column of 1's can't be used! Intercept always included.") : missing value where TRUE/FALSE needed

Below is the source code for the error message for the bestglm function:

#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.")
}

I don't have a column of 1s in my data and I am at a loss as to what that means. Below is the code I am using. Can anyone help please?

#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

Upvotes: 1

Views: 581

Answers (1)

SamPer
SamPer

Reputation: 64

I came across the same error and it was solved by removing NAs in those variables included into the bestglm command. You can get rid of NAs from the original data-frame DF like this:

df <- DF[is.na(DF$foo)==F & is.na(DF$bar)==F,]

If you add those columns that have NAs between the square brackets above, you can then run bestglm on the new data-frame df

Upvotes: 1

Related Questions