How can I subset a variable based on its percentile when using logistic regression

StackOverflow https://stackoverflow.com/questions/23359559

  •  11-07-2023
  •  | 
  •  

سؤال

I have a line of code that calculates logistic regression based on 2 variables where one variable's values are above its mean:

ff <- lrm(Target ~  var1 + , data = dat ,subset = var1>=mean(var1))

I would like to change the mean to a percentile: for example do the subset on observations where the value of var1 is higher than the 7th percentile and less than the 9th percentile.

How can I do it?

هل كانت مفيدة؟

المحلول

Simply:

ff <- lrm( Target ~  var1 + , data = dat ,subset=var1>=quantile(var1, 0.07) & var1<=quantile(var1, 0.09))
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top