sambofra / bnstruct

R package for Bayesian Network Structure Learning
GNU General Public License v3.0
17 stars 11 forks source link

Structure Learning with SEM Algo #16

Closed edd3x closed 4 years ago

edd3x commented 4 years ago

Please I keep this error when I try to learn structure with SEM algorithm

Error in if (obs.val >= quantiles[[obs.var]][node.sizes[obs.var]]) { : missing value where TRUE/FALSE needed

Can you tell me what I am doing wrong, I am using continuous variables with 30% missing data.

albertofranzin commented 4 years ago

It seems it is a bug. Can you give more information to reproduce it? At least the header file, some rows of the data file, and the commands you are using.

edd3x commented 4 years ago

Thanks for the quick response please find a zipped sample data and script attached. Very Great Library BNStruct, thanks

albertofranzin commented 4 years ago

Sorry, I don't see where or how you use the data. Can you please provide a minimal example?

edd3x commented 4 years ago

ScriptData.zip Very sorry I added the wrong script please see attached

edd3x commented 4 years ago

Hello Alberto, Please have you been able to run the sample code, with data provided successfully without the error. I have also realised that you don't have examples codes for cases that involve the use of continuous variables. Thank you

albertofranzin commented 4 years ago

I managed to reproduce the error. I'm looking into it, I'll let you know as soon as I have the chance,

albertofranzin commented 4 years ago

Hello edd3x, the problem you were having should be fixed now. Can you please check whether it's working?

Cby19961020 commented 3 years ago

Hi @albertofranzin , I was just running the code provided by @edd3x with no modification of the code and I ran into a similar error: Error in if (levels[i] == 0) { : missing value where TRUE/FALSE needed

albertofranzin commented 3 years ago

Hi,

in that example there is a problem with the layering provided: (4,2,3,5,1,1,1,1) essentially tries to force a reverse time dependency, the error may arise from there.

You can start with this code (I removed the bootstrap part, for speed of execution):

library(bnstruct)
df1 = read.csv('Weekly_Lag2_Garissa_Sample2copy.csv')
headers1 = c('LST_t0', 'Rainfall_t0', 'SoilMoist_t0', 'VCI_t0','LST_t1', 'Rainfall_t1', 'SoilMoist_t1', 'VCI_t1')
sub_df1 = df1[,headers1]
quants1  = c(5, 5, 5, 5, 5, 5, 5,5)

bn_data1 = BNDataset(data=sub_df1,
                     discreteness=rep('C',8),
                     variables = headers1,
                     node.sizes = c(5,5,5,5,5,5,5,5))

layers = c(1,1,1,1,2,2,2,2)

net5 = learn.network(bn_data1, algo = "sem",
                             use.imputed.data = FALSE,
                             bootstrap=FALSE,
                             layering=layers)

This code works fine for me. If it doesn't for you, please let me know providing as much information as possible.

You can then try to reintroduce the bootstrap and see if there is an error; also in that case, please let me know.