Re: [R] R and .asc file extension

2022-05-20 Thread Francois Morneau

Dear Thomas,

If your .asc file is a raster (Esri ASCII raster format), you may 
consider the functions 'raster' in the raster package or 'read_starts' 
in the star package.


Otherwise (or even)  'scan' or 'read.table' from base/utils may be your 
friends.


Best,

François

Le 20/05/2022 à 15:27, Thomas Subia via R-help a écrit :

Colleagues,

I have data which has a .asc file extension.

Can R read that file extension?

All the best,

Thomas Subia
Statistician


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] missing values error in if statement

2022-05-20 Thread Rui Barradas

Hello,

I'm getting an error when running your code:

learner = lrn("classif.randomForest", predict_type = "prob")
#> Error: Element with key 'classif.randomForest' not found in 
DictionaryLearner!


Rui Barradas

Às 14:12 de 20/05/2022, Neha gupta escreveu:

When I run

print(fc)

it shows 'Inf'. It mean it doesn't calculate the bias/fairness, maybe 
due to missing values.


RF passes 1/5 metrics
Total loss :  Inf



On Fri, May 20, 2022 at 3:06 PM Rui Barradas > wrote:


Hello,

This is a frequent way of coding and a source for questions.


ifelse(test$CE == '2', 1, 0)


is equivalent to the much more performant


as.integer(test$CE == '2')   # or as.numeric


If the code still runs with errors, then those errors came from
elsewhere.

Hope this helps,

Rui Barradas


Às 09:16 de 20/05/2022, Neha gupta escreveu:
 > I am sorry.. The code is here and data is provided at the end of this
 > email.
 >
 > data = readARFF("aho.arff")
 >
 > index= sample(1:nrow(data), 0.7*nrow(data))
 > train= data[index,]
 > test= data[-index,]
 >
 > task = TaskClassif$new("data", backend = train, target = "isKilled")
 > learner= lrn("classif.randomForest", predict_type = "prob")
 > model= learner$train(task )
 >
 > ///explainer is created to identify a bias in a particular
feature i.e. CE
 > feature in this case
 >
 > explainer = explain_mlr3(model,
 >                           data = test[,-15],
 >                           y = as.numeric(test$isKilled)-1,
 >                           label="RF")
 > prot <- ifelse(test$CE == '2', 1, 0)       /// Error comes here
 > privileged <- '1'
 >
 >
 > fc= fairness_check(explainer,
 >                            protected = prot,
 >                     privileged = privileged)
 > plot(fc)
 >
 >
 > // my data is
 >
 > dput(test)
 > structure(list(DepthTree = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
 > 2, 2, 2, 1, 1, 1, 1, 2, 1), NumSubclass = c(0, 0, 0, 0, 0, 0,
 > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 > 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2), McCabe = c(1, 1, 1,
 > 3, 3, 3, 3, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1, 2, 2, 1,
 > 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5,
 > 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5,
 > 5, 5, 5, 5, 5, 5, 2, 2, 2, 2, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
 > 5, 5, 5, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 4, 4, 1, 1, 2, 2, 2, 2,
 > 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), LOC = c(3,
 > 3, 4, 10, 10, 10, 10, 4, 5, 22, 22, 22, 22, 22, 22, 22, 22, 3,
 > 3, 3, 3, 8, 8, 4, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
 > 23, 23, 23, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8,
 > 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20,
 > 20, 20, 20, 20, 20, 7, 7, 7, 7, 18, 18, 18, 18, 18, 18, 15, 15,
 > 15, 15, 15, 15, 15, 15, 6, 6, 6, 15, 15, 15, 15, 15, 15, 9, 9,
 > 9, 9, 9, 9, 9, 4, 4, 3, 3, 3, 3, 4, 4, 4, 5, 8, 8, 3, 3, 3, 7,
 > 7, 3, 3, 15, 15, 15, 15, 15, 15, 15, 15, 3, 3, 3, 4, 4, 4, 4,
 > 8, 8, 8, 8, 4, 3), DepthNested = c(1, 1, 1, 2, 2, 2, 2, 1, 2,
 > 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 3, 3,
 > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
 > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
 > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1,
 > 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), CA = c(1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
 > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 

Re: [R] missing values error in if statement

2022-05-20 Thread PIKAL Petr
Hm,

what do **you** mean by fraction

This is what you posted

> >> >Error in if (fraction <= 1) { : missing value where TRUE/FALSE
> >> >needed
On May 19, 2022 2:30:58 PM PDT, Neha gupta

I just showed that if object **fraction** is NA, it results exactly in the 
error you posted. From where is this object I do not know.

>From help page
protected
factor, protected variable (also called sensitive attribute), containing 
privileged and unprivileged groups

should be factor, which is not. Maybe it does not matter but you could try to 
change it to one by as.factor function.

You probably modified the code from help page but in that case you should 
check if all your objects are the same mode and structure as the objects in 
help page code.

Cheers
Petr

From: Neha gupta 
Sent: Friday, May 20, 2022 3:22 PM
To: PIKAL Petr 
Cc: r-help mailing list 
Subject: Re: [R] missing values error in if statement

What do you mean by "fraction" ?

traceback()
4: readable_number(max_value - min_value, FALSE)
3: get_nice_ticks(lower_bound, upper_bound)
2: plot.fairness_object(fc)
1: plot(fc)

On Fri, May 20, 2022 at 3:18 PM PIKAL Petr  
wrote:
Hallo

>From what you say the error comes from

> fraction <- NA
> if(fraction <= 1) print(5)
Error in if (fraction <= 1) print(5) :
  missing value where TRUE/FALSE needed
>
so somewhere fraction is set to NA during your code.

I would consult traceback, you could try debug used functions but maybe you
should start with explainer, prot and privileged, if they are as expected by
fairness_check

> > fc= fairness_check(explainer,
> >   protected = prot,
> >privileged = privileged)

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of Neha gupta
> Sent: Friday, May 20, 2022 3:03 PM
> To: Jeff Newmiller 
> Cc: r-help mailing list 
> Subject: Re: [R] missing values error in if statement
>
> Actually I am not very sure where exactly the error raised but when I run
the
> plot(fc) , it shows the error.
>
> I checked it online and people suggested that it may come with missing
> values in 'if' or 'while; statements etc.
>
> I do not know how your code works and mine not.
>
> Best regards
>
> On Fri, May 20, 2022 at 10:16 AM Neha gupta
> 
> wrote:
>
> > I am sorry.. The code is here and data is provided at the end of this
> > email.
> >
> > data = readARFF("aho.arff")
> >
> > index= sample(1:nrow(data), 0.7*nrow(data)) train= data[index,] test=
> > data[-index,]
> >
> > task = TaskClassif$new("data", backend = train, target = "isKilled")
> > learner= lrn("classif.randomForest", predict_type = "prob") model=
> > learner$train(task )
> >
> > ///explainer is created to identify a bias in a particular feature
> > i.e. CE feature in this case
> >
> > explainer = explain_mlr3(model,
> >  data = test[,-15],
> >  y = as.numeric(test$isKilled)-1,
> >  label="RF")
> > prot <- ifelse(test$CE == '2', 1, 0)   /// Error comes here
> > privileged <- '1'
> >
> >
> > fc= fairness_check(explainer,
> >   protected = prot,
> >privileged = privileged)
> > plot(fc)
> >
> >
> >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, 2, 2, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> > 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> > 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 2, 2, 5, 5, 5, 5, 5,
> > 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
> > 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 4, 4, 1, 1, 2, 2,
> > 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), LOC = c(3,
> > 3, 4, 10, 10, 10, 10, 4, 5, 22, 22, 22, 22, 22, 22, 22, 22, 3, 3, 3,
> > 3, 8, 8, 4, 23, 

Re: [R] missing values error in if statement

2022-05-20 Thread Neha gupta
Actually it's found in a library (mlr3extralearners). I have already
imported this library in my code.

On Friday, May 20, 2022, Rui Barradas  wrote:

> Hello,
>
> I'm getting an error when running your code:
>
> learner = lrn("classif.randomForest", predict_type = "prob")
> #> Error: Element with key 'classif.randomForest' not found in
> DictionaryLearner!
>
> Rui Barradas
>
> Às 14:12 de 20/05/2022, Neha gupta escreveu:
>
>> When I run
>>
>> print(fc)
>>
>> it shows 'Inf'. It mean it doesn't calculate the bias/fairness, maybe due
>> to missing values.
>>
>> RF passes 1/5 metrics
>> Total loss :  Inf
>>
>>
>>
>> On Fri, May 20, 2022 at 3:06 PM Rui Barradas > > wrote:
>>
>> Hello,
>>
>> This is a frequent way of coding and a source for questions.
>>
>>
>> ifelse(test$CE == '2', 1, 0)
>>
>>
>> is equivalent to the much more performant
>>
>>
>> as.integer(test$CE == '2')   # or as.numeric
>>
>>
>> If the code still runs with errors, then those errors came from
>> elsewhere.
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>>
>> Às 09:16 de 20/05/2022, Neha gupta escreveu:
>>  > I am sorry.. The code is here and data is provided at the end of
>> this
>>  > email.
>>  >
>>  > data = readARFF("aho.arff")
>>  >
>>  > index= sample(1:nrow(data), 0.7*nrow(data))
>>  > train= data[index,]
>>  > test= data[-index,]
>>  >
>>  > task = TaskClassif$new("data", backend = train, target =
>> "isKilled")
>>  > learner= lrn("classif.randomForest", predict_type = "prob")
>>  > model= learner$train(task )
>>  >
>>  > ///explainer is created to identify a bias in a particular
>> feature i.e. CE
>>  > feature in this case
>>  >
>>  > explainer = explain_mlr3(model,
>>  >   data = test[,-15],
>>  >   y = as.numeric(test$isKilled)-1,
>>  >   label="RF")
>>  > prot <- ifelse(test$CE == '2', 1, 0)   /// Error comes here
>>  > privileged <- '1'
>>  >
>>  >
>>  > fc= fairness_check(explainer,
>>  >protected = prot,
>>  > privileged = privileged)
>>  > plot(fc)
>>  >
>>  >
>>  > // my data is
>>  >
>>  > dput(test)
>>  > structure(list(DepthTree = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>  > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>  > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>  > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>  > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>  > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
>>  > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
>>  > 2, 2, 2, 1, 1, 1, 1, 2, 1), NumSubclass = c(0, 0, 0, 0, 0, 0,
>>  > 0, 0, 0, 0, 0, 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 23, 23, 23,
>>  > 23, 23, 23, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8,
>>  > 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20,
>>  > 20, 20, 20, 20, 20, 7, 7, 7, 7, 18, 18, 18, 18, 18, 18, 15, 15,
>>  > 15, 15, 15, 15, 15, 15, 6, 6, 6, 15, 15, 15, 15, 15, 15, 9, 9,
>>  > 9, 9, 9, 9, 9, 4, 4, 3, 3, 3, 3, 4, 4, 4, 5, 8, 8, 3, 3, 3, 7,
>>  > 7, 3, 3, 15, 15, 15, 15, 15, 15, 15, 15, 3, 3, 3, 4, 4, 4, 4,
>>  > 8, 8, 8, 8, 4, 3), DepthNested = c(1, 1, 1, 2, 2, 2, 2, 1, 2,
>>  > 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 3, 3,
>>  > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
>>  > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
>>  > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
>>  > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 

Re: [R] R and .asc file extension

2022-05-20 Thread Ebert,Timothy Aaron
A google search returned a stack overflow page that might help.
stackoverflow.com/questions/20177581/reading-an-asc-file-into-r
(add the https part to get a functional link.)

I would also try looking at the file using something like notebook, or any 
program that is a plain text editor. That way I can see exactly what the file 
contains.

Tim




-Original Message-
From: R-help  On Behalf Of Thomas Subia via R-help
Sent: Friday, May 20, 2022 9:27 AM
To: r-help@r-project.org
Subject: [R] R and .asc file extension

[External Email]

Colleagues,

I have data which has a .asc file extension.

Can R read that file extension?

All the best,

Thomas Subia
Statistician

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=OuZijT4yJ8dfQLVPVj4YWSCPkpUW4wkGCSHim27tbH9qYMjXbuMSxybv7i0cvWHl=7eUP-gSu0ZAEL_iEdxyJwCEEE7PQF15Fplf_dGvzMfM=
PLEASE do read the posting guide 
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html=DwICAg=sJ6xIWYx-zLMB3EPkvcnVg=9PEhQh2kVeAsRzsn7AkP-g=OuZijT4yJ8dfQLVPVj4YWSCPkpUW4wkGCSHim27tbH9qYMjXbuMSxybv7i0cvWHl=0Y81eoA64cMK6zoqQGZoDecTemarTEV4UxqvF-FSuMA=
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R and .asc file extension

2022-05-20 Thread Uwe Ligges




On 20.05.2022 15:27, Thomas Subia via R-help wrote:

Colleagues,

I have data which has a .asc file extension.


asc likely means ASCII and can be any kind of text data, so wed need 
some contents to suggest a function. But any for text files should work.

Best,
Uwe Ligges


Can R read that file extension?

All the best,

Thomas Subia
Statistician

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] missing values error in if statement

2022-05-20 Thread Neha gupta
When I run

print(fc)

it shows 'Inf'. It mean it doesn't calculate the bias/fairness, maybe due
to missing values.

RF passes 1/5 metrics
Total loss :  Inf



On Fri, May 20, 2022 at 3:06 PM Rui Barradas  wrote:

> Hello,
>
> This is a frequent way of coding and a source for questions.
>
>
> ifelse(test$CE == '2', 1, 0)
>
>
> is equivalent to the much more performant
>
>
> as.integer(test$CE == '2')   # or as.numeric
>
>
> If the code still runs with errors, then those errors came from elsewhere.
>
> Hope this helps,
>
> Rui Barradas
>
>
> Às 09:16 de 20/05/2022, Neha gupta escreveu:
> > I am sorry.. The code is here and data is provided at the end of this
> > email.
> >
> > data = readARFF("aho.arff")
> >
> > index= sample(1:nrow(data), 0.7*nrow(data))
> > train= data[index,]
> > test= data[-index,]
> >
> > task = TaskClassif$new("data", backend = train, target = "isKilled")
> > learner= lrn("classif.randomForest", predict_type = "prob")
> > model= learner$train(task )
> >
> > ///explainer is created to identify a bias in a particular feature i.e.
> CE
> > feature in this case
> >
> > explainer = explain_mlr3(model,
> >   data = test[,-15],
> >   y = as.numeric(test$isKilled)-1,
> >   label="RF")
> > prot <- ifelse(test$CE == '2', 1, 0)   /// Error comes here
> > privileged <- '1'
> >
> >
> > fc= fairness_check(explainer,
> >protected = prot,
> > privileged = privileged)
> > plot(fc)
> >
> >
> > // my data is
> >
> > dput(test)
> > structure(list(DepthTree = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 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 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), LOC = c(3,
> > 3, 4, 10, 10, 10, 10, 4, 5, 22, 22, 22, 22, 22, 22, 22, 22, 3,
> > 3, 3, 3, 8, 8, 4, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
> > 23, 23, 23, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8,
> > 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20,
> > 20, 20, 20, 20, 20, 7, 7, 7, 7, 18, 18, 18, 18, 18, 18, 15, 15,
> > 15, 15, 15, 15, 15, 15, 6, 6, 6, 15, 15, 15, 15, 15, 15, 9, 9,
> > 9, 9, 9, 9, 9, 4, 4, 3, 3, 3, 3, 4, 4, 4, 5, 8, 8, 3, 3, 3, 7,
> > 7, 3, 3, 15, 15, 15, 15, 15, 15, 15, 15, 3, 3, 3, 4, 4, 4, 4,
> > 8, 8, 8, 8, 4, 3), DepthNested = c(1, 1, 1, 2, 2, 2, 2, 1, 2,
> > 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 3, 3,
> > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> > 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
> > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1,
> > 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), CA = c(1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> > 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> > 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> > 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), CE = c(2, 2, 2, 2, 2,
> > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> > 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0,
> > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> > 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 

Re: [R] missing values error in if statement

2022-05-20 Thread PIKAL Petr
Hi 

Strange, you say

> prot <- ifelse(test$CE == '2', 1, 0)   /// Error comes here

but with your data

ifelse(test$CE == '2', 1, 0)
  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1
 [38] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0
 [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0
[112] 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 1 1

the code runs smoothly without error.

Cheers
Petr


> -Original Message-
> From: R-help  On Behalf Of Neha gupta
> Sent: Friday, May 20, 2022 10:16 AM
> To: Jeff Newmiller 
> Cc: r-help mailing list 
> Subject: Re: [R] missing values error in if statement
> 
> I am sorry.. The code is here and data is provided at the end of this
> email.
> 
> data = readARFF("aho.arff")
> 
> index= sample(1:nrow(data), 0.7*nrow(data))
> train= data[index,]
> test= data[-index,]
> 
> task = TaskClassif$new("data", backend = train, target = "isKilled")
> learner= lrn("classif.randomForest", predict_type = "prob")
> model= learner$train(task )
> 
> ///explainer is created to identify a bias in a particular feature i.e. CE
> feature in this case
> 
> explainer = explain_mlr3(model,
>  data = test[,-15],
>  y = as.numeric(test$isKilled)-1,
>  label="RF")
> prot <- ifelse(test$CE == '2', 1, 0)   /// Error comes here
> privileged <- '1'
> 
> 
> fc= fairness_check(explainer,
>   protected = prot,
>privileged = privileged)
> plot(fc)
> 
> 
> // my data is
> 
> dput(test)
> structure(list(DepthTree = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1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, 1, 1, 1, 2, 2, 2, 2, 1, 1), LOC = c(3,
> 3, 4, 10, 10, 10, 10, 4, 5, 22, 22, 22, 22, 22, 22, 22, 22, 3,
> 3, 3, 3, 8, 8, 4, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
> 23, 23, 23, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 8, 8,
> 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 20, 20, 20, 20, 20, 20,
> 20, 20, 20, 20, 20, 7, 7, 7, 7, 18, 18, 18, 18, 18, 18, 15, 15,
> 15, 15, 15, 15, 15, 15, 6, 6, 6, 15, 15, 15, 15, 15, 15, 9, 9,
> 9, 9, 9, 9, 9, 4, 4, 3, 3, 3, 3, 4, 4, 4, 5, 8, 8, 3, 3, 3, 7,
> 7, 3, 3, 15, 15, 15, 15, 15, 15, 15, 15, 3, 3, 3, 4, 4, 4, 4,
> 8, 8, 8, 8, 4, 3), DepthNested = c(1, 1, 1, 2, 2, 2, 2, 1, 2,
> 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 2, 2, 1, 3, 3, 3, 3, 3, 3,
> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1,
> 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1), CA = c(1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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