Re: [R] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

2022-01-26 Thread PIKAL Petr
Hi

Actually you did not. Your original question was:

> Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
> I used this:
> var <- ifelse(test$operator == 'T14', 1, 0)
> operator has several values like T1, T3, T7, T15, T31, T37
> For some values like T3, T7 it works fine but for majority of values
> it gives error.
> When I use: is.na(ts$operator), it shows all false values so no NAs.

Only now we could inspect your whole code and it was already pointed that the 
error does not originate from ifelse.

With the same data and ifelse code I did not get any error.

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,


> str(test)
'data.frame':   146 obs. of  15 variables:
 $ DepthTree: num  1 1 1 1 1 1 1 1 1 1 ...
 
$ numCovered   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ operator : Factor w/ 16 levels "T0","T1","T2",..: 4 4 7 8 8 8 11 4 10 7 
...
 $ methodReturn : Factor w/ 22 levels "I","V","Z","method",..: 2 2 2 2 2 2 2 4 
4 2 ...
 $ numTestsCover: num  16 15 15 16 15 15 15 4 4 16 ...
 $ mutantAssert : num  55 55 55 55 55 55 55 13 13 55 ...
 $ classAssert  : num  3 3 3 3 3 3 3 3 3 3 ...
 $ isKilled : Factor w/ 2 levels "yes","no": 2 2 2 2 2 2 2 2 2 2 ...
>
prot <- ifelse(test$operator == 'T13', 1, 0)

the most probable source of the error is

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

so you should check explainer and privileged

Cheers
Petr

From: javed khan 
Sent: Wednesday, January 26, 2022 3:45 PM
To: PIKAL Petr 
Cc: R-help 
Subject: Re: [R] Error in if (fraction <= 1) { : missing value where 
TRUE/FALSE needed

Hi Pikal, why would I hide something? I provided just a code where error is.

Full code is:

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.gbm", predict_type = "prob")

model= learner$train(task )

explainer = explain_mlr3(model,
 data = test[,-15],
 y = as.numeric(test$isKilled)-1,
 label="GBM")

prot <- ifelse(test$operator == 'T13', 1, 0)
privileged <- '1'

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


And my data is the following:

str(test)
'data.frame': 146 obs. of  15 variables:
 $ DepthTree: num  1 1 1 1 1 1 1 1 1 1 ...
 $ NumSubclass  : num  0 0 0 0 0 0 0 0 0 0 ...
 $ McCabe   : num  1 3 3 3 3 3 3 1 1 2 ...
 $ LOC  : num  3 10 10 10 10 10 10 4 4 5 ...
 $ DepthNested  : num  1 2 2 2 2 2 2 1 1 2 ...
 $ CA   : num  1 1 1 1 1 1 1 1 1 1 ...
 $ CE   : num  2 2 2 2 2 2 2 2 2 2 ...
 $ Instability  : num  0.667 0.667 0.667 0.667 0.667 0.667 0.667 0.667 0.667 
0.667 ...
 $ numCovered   : num  0 0 0 0 0 0 0 0 0 0 ...
 $ operator : Factor w/ 16 levels "T0","T1","T2",..: 4 4 7 8 8 8 11 4 10 7 
...
 $ methodReturn : Factor w/ 22 levels "I","V","Z","method",..: 2 2 2 2 2 2 2 4 
4 2 ...
 $ numTestsCover: num  16 15 15 16 15 15 15 4 4 16 ...
 $ mutantAssert : num  55 55 55 55 55 55 55 13 13 55 ...
 $ classAssert  : num  3 3 3 3 3 3 3 3 3 3 ...
 $ isKilled : Factor w/ 2 levels "yes","no": 2 2 2 2 2 2 2 2 2 2 ...
> 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, 1,
1, 1, 2, 2, 1, 2, 1, 1, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2), McCabe = c(1, 3, 3,
3, 3, 3, 3, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1, 2,
2, 2, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 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, 2, 2, 2,
2, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2, 2, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1), LOC = c(3,
10, 10, 10, 10, 10, 10, 4, 4, 5, 22, 22, 22, 22, 22, 22, 22,
22, 3, 3, 3, 3, 3, 8, 8, 8, 4, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 16, 16, 16, 16, 16, 16, 8, 8, 

Re: [R] Simulate type I error

2022-01-26 Thread Bert Gunter
Please note:

" I did post the plain text but maybe the default font of my gmail
makes it look like being formatted."

I assume this must be false, because the list server detected html and
posted "[[alternative HTML version deleted]]" after your email. You
have to explicitly choose "Plain text mode" in gmail as its default is
html.

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Wed, Jan 26, 2022 at 1:04 PM Chao Liu  wrote:
>
> Hi Jeff,
>
> Thanks for the reminder. I will post my question there. I did post the
> plain text but maybe the default font of my gmail makes it look like being
> formatted.
>
> Best,
>
> Chao
>
> On Wed, Jan 26, 2022 at 2:49 PM Jeff Newmiller 
> wrote:
>
> > You might get a response here, but the R-sig-mixed-models mailing list is
> > a more appropriate place for this. See the Posting Guide mentioned in the
> > footer.
> >
> > Also, post using plain text... formatted email may not communicate what
> > you expected it to communicate.
> >
> > On January 26, 2022 11:12:36 AM PST, Chao Liu 
> > wrote:
> > >Dear R-help community,
> > >
> > >I would like to simulate type I error for a random-effects model I
> > >generated.
> > >
> > >The statistic of interest is standard deviations of the random intercept
> > >and random slope. Specifically, for random intercept, H_{0}: lambda_{0} =2
> > >and H_{1}: lambda_{0} not equal to 2; for random slope, H_{0}: lambda_{1}
> > >=1 and H_{1}: lambda_{1} not equal to 1. I assume the test would be
> > >likelihood ratio test but please correct me if I am wrong. How do I assess
> > >type I error for the random-effects model I specified below:
> > >
> > >set.seed(323)
> > >#The following code is to specify the structure and parameters of the
> > >random-effects model
> > >dtfunc = function(nsub){
> > >  time = 0:9
> > >  rt = c()
> > >  time.all = rep(time, nsub)
> > >  subid.all = as.factor(rep(1:nsub, each = length(time)))
> > >
> > >  # Step 1:  Specify the lambdas.
> > >  G = matrix(c(2^2, 0, 0, 1^2), nrow = 2)
> > >  int.mean = 251
> > >  slope.mean = 10
> > >  sub.ints.slopes = mvrnorm(nsub, c(int.mean, slope.mean), G)
> > >  sub.ints = sub.ints.slopes[,1]
> > >  time.slopes = sub.ints.slopes[,2]
> > >
> > >  # Step 2:  Use the intercepts and slopes to generate RT data
> > >  sigma = 30
> > >  for (i in 1:nsub){
> > >rt.vec = sub.ints[i] + time.slopes[i]*time + rnorm(length(time), sd =
> > >sigma)
> > >rt = c(rt, rt.vec)
> > >  }
> > >
> > >  dat = data.frame(rt, time.all, subid.all)
> > >  return(dat)
> > >}
> > >
> > >#Here I run one random-effects model
> > >set.seed(10)
> > >dat = dtfunc(16)
> > >lmer(rt~time.all + (1+time.all |subid.all), dat)
> > >
> > >Assuming the test for significance is likelihood ratio test and so in the
> > >end, I want to see if I run the test 1000 times, what is the probability
> > of
> > >rejecting null hypothesis when it is TRUE. Also, how do I plot the
> > behavior
> > >of type I error if I change the values of standard deviations?
> > >
> > >Any help is appreciated!
> > >
> > >Best,
> > >
> > >Chao
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > >__
> > >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.
> >
> > --
> > Sent from my phone. Please excuse my brevity.
> >
>
> [[alternative HTML version deleted]]
>
> __
> 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.


[R] Simulate type I error

2022-01-26 Thread Chao Liu
Dear R-help community,

I would like to simulate type I error for a random-effects model I
generated.

The statistic of interest is standard deviations of the random intercept
and random slope. Specifically, for random intercept, H_{0}: lambda_{0} =2
and H_{1}: lambda_{0} not equal to 2; for random slope, H_{0}: lambda_{1}
=1 and H_{1}: lambda_{1} not equal to 1. I assume the test would be
likelihood ratio test but please correct me if I am wrong. How do I assess
type I error for the random-effects model I specified below:

set.seed(323)
#The following code is to specify the structure and parameters of the
random-effects model
dtfunc = function(nsub){
  time = 0:9
  rt = c()
  time.all = rep(time, nsub)
  subid.all = as.factor(rep(1:nsub, each = length(time)))

  # Step 1:  Specify the lambdas.
  G = matrix(c(2^2, 0, 0, 1^2), nrow = 2)
  int.mean = 251
  slope.mean = 10
  sub.ints.slopes = mvrnorm(nsub, c(int.mean, slope.mean), G)
  sub.ints = sub.ints.slopes[,1]
  time.slopes = sub.ints.slopes[,2]

  # Step 2:  Use the intercepts and slopes to generate RT data
  sigma = 30
  for (i in 1:nsub){
rt.vec = sub.ints[i] + time.slopes[i]*time + rnorm(length(time), sd =
sigma)
rt = c(rt, rt.vec)
  }

  dat = data.frame(rt, time.all, subid.all)
  return(dat)
}

#Here I run one random-effects model
set.seed(10)
dat = dtfunc(16)
lmer(rt~time.all + (1+time.all |subid.all), dat)

Assuming the test for significance is likelihood ratio test and so in the
end, I want to see if I run the test 1000 times, what is the probability of
rejecting null hypothesis when it is TRUE. Also, how do I plot the behavior
of type I error if I change the values of standard deviations?

Any help is appreciated!

Best,

Chao

[[alternative HTML version deleted]]

__
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] Linear

2022-01-26 Thread Val
str(dat2)
data.frame': 37654 obs. ...:
 $ Yld: int
 $ A   : int
 $ B   : chr
 $ C   : chr

On Wed, Jan 26, 2022 at 10:49 AM Bert Gunter  wrote:

> What does str(dat2) give?
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Wed, Jan 26, 2022 at 7:37 AM Val  wrote:
> >
> > Hi all,
> >
> > I am trying to get the lsmeans for one of the factors  fitted in the
> > following model
> >
> > Model1 = lm(Yld ~ A + B + C, data = dat2)
> > M_lsm =  as.data.frame(lsmeans(Model1, "C")),
> >
> > My problem is, I am getting this error message.
> > "Error: The rows of your requested reference grid would be 81412, which
> > exceeds the limit of 1 (not including any multivariate responses)".
> >
> > How do I fix this?
> >
> > Thank you
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > 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.
>

[[alternative HTML version deleted]]

__
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] Linear

2022-01-26 Thread Bert Gunter
What does str(dat2) give?

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Wed, Jan 26, 2022 at 7:37 AM Val  wrote:
>
> Hi all,
>
> I am trying to get the lsmeans for one of the factors  fitted in the
> following model
>
> Model1 = lm(Yld ~ A + B + C, data = dat2)
> M_lsm =  as.data.frame(lsmeans(Model1, "C")),
>
> My problem is, I am getting this error message.
> "Error: The rows of your requested reference grid would be 81412, which
> exceeds the limit of 1 (not including any multivariate responses)".
>
> How do I fix this?
>
> Thank you
>
> [[alternative HTML version deleted]]
>
> __
> 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.


[R] Linear

2022-01-26 Thread Val
Hi all,

I am trying to get the lsmeans for one of the factors  fitted in the
following model

Model1 = lm(Yld ~ A + B + C, data = dat2)
M_lsm =  as.data.frame(lsmeans(Model1, "C")),

My problem is, I am getting this error message.
"Error: The rows of your requested reference grid would be 81412, which
exceeds the limit of 1 (not including any multivariate responses)".

How do I fix this?

Thank you

[[alternative HTML version deleted]]

__
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] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

2022-01-26 Thread Jeff Newmiller
Your error and your code don't match. Please spend some time to make a small 
reproducible example [1][2] when posting a question... you may even figure out 
your own answer before you send it out.

[1] 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

On January 26, 2022 5:47:16 AM PST, javed khan  wrote:
>I get this error:
>
>Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
>
>I used this:
>
>var <- ifelse(test$operator == 'T14', 1, 0)
>
>operator has several values like T1, T3, T7, T15, T31, T37
>
>For some values like T3, T7 it works fine but for majority of values it
>gives error.
>
>When I use: is.na(ts$operator), it shows all false values so no NAs.
>
>Where could be the problem?
>
>   [[alternative HTML version deleted]]
>
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

2022-01-26 Thread PIKAL Petr
Hi

It seems that you are hiding what you really do. 

This
> options(error = NULL)
works fine without any error. So please If you want some reasonable answer
post question with data and code which is causing the error.

My wild guess is that you have some objects in your environment and you do
not know that they are used in you commands. Try to start fresh R session
and try to inspect your environment with 

ls()

Cheers
Petr

> -Original Message-
> From: R-help  On Behalf Of javed khan
> Sent: Wednesday, January 26, 2022 3:05 PM
> To: Ivan Krylov 
> Cc: R-help 
> Subject: Re: [R] Error in if (fraction <= 1) { : missing value where
TRUE/FALSE
> needed
> 
> Ivan, thanks
> 
> When I use options(error = NULL)
> 
> it says: Error during wrapup: missing value where TRUE/FALSE needed
> Error: no more error handlers available (recursive errors?); invoking
'abort'
> restart
> 
> With traceback(), I get
> 
> 4: readable_number(max_value - min_value, FALSE)
> 3: get_nice_ticks(lower_bound, upper_bound)
> 
> On Wed, Jan 26, 2022 at 2:53 PM Ivan Krylov  wrote:
> 
> > On Wed, 26 Jan 2022 14:47:16 +0100
> > javed khan  wrote:
> >
> > > Error in if (fraction <= 1) { : missing value where TRUE/FALSE
> > > needed
> >
> > > var <- ifelse(test$operator == 'T14', 1, 0)
> >
> > The error must be in a place different from your test$operator
> > comparison. Have you tried traceback() to get the call stack leading
> > to the error? Or options(error = recover) to land in a debugger
> > session the moment an uncaught error happens? (Use options(error =
> > NULL) to go back to the default behaviour.)
> >
> > Unrelated: var <- test$operator == 'T14' will also give you an
> > equivalent logical vector with a bit less work.
> >
> > --
> > Best regards,
> > Ivan
> >
> 
>   [[alternative HTML version deleted]]
> 
> __
> 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] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

2022-01-26 Thread PIKAL Petr
Hi

Do not post in HTML, please.
Try to show your real data - use str(test), or preferably dput(test). If
test is big, use only fraction of it
The problem must be probably in your data.

x <- sample(1:20, 100, replace=T)
fake <- paste("T", x, sep="")
ifelse(fake=="T14", 1,0) 
  [1] 0 0 0 0 0 0 0 0 0 0 0 0 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
 [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 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 1 0
 
head(fake)
[1] "T7"  "T9"  "T3"  "T9"  "T12" "T9" 
> str(fake)
 chr [1:100] "T7" "T9" "T3" "T9" "T12" "T9" "T19" "T19" "T12" "T2" "T17" ...
>
Cheers
Petr


> -Original Message-
> From: R-help  On Behalf Of javed khan
> Sent: Wednesday, January 26, 2022 2:47 PM
> To: R-help 
> Subject: [R] Error in if (fraction <= 1) { : missing value where
TRUE/FALSE
> needed
> 
> I get this error:
> 
> Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed
> 
> I used this:
> 
> var <- ifelse(test$operator == 'T14', 1, 0)
> 
> operator has several values like T1, T3, T7, T15, T31, T37
> 
> For some values like T3, T7 it works fine but for majority of values it
gives error.
> 
> When I use: is.na(ts$operator), it shows all false values so no NAs.
> 
> Where could be the problem?
> 
>   [[alternative HTML version deleted]]
> 
> __
> 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] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

2022-01-26 Thread Ivan Krylov
On Wed, 26 Jan 2022 14:47:16 +0100
javed khan  wrote:

> Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

> var <- ifelse(test$operator == 'T14', 1, 0)

The error must be in a place different from your test$operator
comparison. Have you tried traceback() to get the call stack leading to
the error? Or options(error = recover) to land in a debugger session
the moment an uncaught error happens? (Use options(error = NULL) to go
back to the default behaviour.)

Unrelated: var <- test$operator == 'T14' will also give you an
equivalent logical vector with a bit less work.

-- 
Best regards,
Ivan

__
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] Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

2022-01-26 Thread javed khan
I get this error:

Error in if (fraction <= 1) { : missing value where TRUE/FALSE needed

I used this:

var <- ifelse(test$operator == 'T14', 1, 0)

operator has several values like T1, T3, T7, T15, T31, T37

For some values like T3, T7 it works fine but for majority of values it
gives error.

When I use: is.na(ts$operator), it shows all false values so no NAs.

Where could be the problem?

[[alternative HTML version deleted]]

__
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] Need help with writing survey design for multilevel analysis

2022-01-26 Thread Love Umesi
Hello,

I am new in using R, and I need to run a multilevel analysis (on two
levels) using Cox frailty survival model on a survey data (Nigeria
Demographic and Health Survey Data).

My problem is how to write the design weight using the two weights needed
and apply them to the analysis.

I have identified the needed variables for the survey design, which are :

psu/cluster=~v021
individual-level weight=~wt1_1
cluster-level weigh=~wt2_1
strata/stratum=~v022

Please can someone help me with the survey design (svydesign) code and how
to include it and the weights in a model.

I have tried to generate a minimum reproducible data

To view the minimum reproducible data: datapasta::df_paste (head(rcom2018,
10)[, c('pid', 'study_time', 'died', 'v021', 'v022', 'wt2_1', 'wt1_1',
'v024', 'v025', 'mat_edu')])


I understand I have to use svycoxph in the model. Please how do I include
survey design and account for the 2 weights in the gamma frailty model
below?

Frailty1 <- coxph (Surv(study_time, died) ~ factor(v024) + factor(mat_edu)
+ v025 + frailty(v021,distribution="gamma"), data=rcom2018)


Really looking forward to your help as my project is hanging on this.

Many thanks.

Love Umesi

library(survey)#> Warning: package 'survey' was built under R version
4.0.5#> Loading required package: grid#> Loading required package:
Matrix#> Loading required package: survival#> Warning: package
'survival' was built under R version 4.0.5#> #> Attaching package:
'survey'#> The following object is masked from 'package:graphics':#>
#> dotchart
library(survival)


rcom1 <- data.frame(
 pid = c(1,2,3,4,
 5,6,7,8,9,10,11,12,13,14,15,16,17,
 18,19,20,21,22,23,24,25,26,27,28,29,
 30,31,32,33,34,35,36,37,38,39,40,
 41,42,43,44,45,46,47,48,49,50),
  study_time = c(13,9,17,
 31,39,22,24,0,23,12,9,35,18,20,60,
 18,5,46,26,54,37,51,31,55,27,15,39,6,
 29,0,9,40,23,12,35,56,14,40,57,42,
 5,42,39,39,54,19,52,42,7,28),
died = c(0,0,0,0,
 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
v021 = c(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,3,
 3,3,3,3,3,3,3,3,3,3,3,3,3,4,4),
v022 = 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"),
v012 = c(40,37,27,
 27,24,32,35,35,34,20,28,28,26,24,24,
 25,26,26,26,26,28,27,25,25,27,26,
 26,21,21,31,36,36,27,23,32,32,33,33,
 33,28,25,37,33,34,33,28,28,29,33,33),
   wt2_1 =
c(401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031,
 401.200012207031,401.200012207031,

401.200012207031,401.200012207031,401.200012207031),
   wt1_1 =
c(2.5074667930603,2.5074667930603,2.5074667930603,

2.5074667930603,2.5074667930603,2.5074667930603,

2.5074667930603,2.5074667930603,2.5074667930603,
 2.5074667930603,2.5074667930603,

2.5074667930603,2.5074667930603,2.5074667930603,

2.5074667930603,5.1194109916687,5.1194109916687,

5.1194109916687,5.1194109916687,5.1194109916687,