dataset - Conditional Prob in R -


i have large data set having more 45 categories of drugs. how find out conditional probability of category ab given ac there every id. 1, 2,3, etc., unique ids.

my dataset looks like

id1.ab ad ac fg ab dc gm ac id2.ab ac dg gm id3.ab dg gm ac 

can in r. tried using prob function in r giving me error.

ps: categories not consecutive. considering each category unique every id irrespective of no of times appears.

i may confused looking for, simple conditional probability seems following:

# create dataset mystring = c("ad", "ac", "bd", "dc")  k = null for(i in 1:45){   samp = sample(mystring, 3, replace = t)   k = c(k,paste(samp, collapse = " ") ) }  st = data.frame(1:45, k, stringsasfactors = f)  library(stringr)  # number of strings contain both groups or  # occurances of intersection alpha = str_detect(st[,2],"ac") & str_detect(st[,2],"ad")   # occurances of ac beta = str_detect(st[,2], "ac")  # p(a \ b) / p(b) (sum(alpha)/45) /    (sum(beta)/45) 

also, assumed categories stored strings based on data sample provided.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -