Home > Mobile >  Please help! I need to include "not on the same identifier" on my function in R how can I
Please help! I need to include "not on the same identifier" on my function in R how can I

Time:11-14

I have a function for classification, where I need to include "not on the same identifier" based on the selection criteria but I am not sure how to include this. Below are the details:

Function: Classification of a disease based on measurements of al and pd:

classifyPerio <- function(x) {
  if (x$num_teeth_al_6mm >= 2 & x$num_teeth_pd_5mm >= 1) {
    return("Severe")
  }
  if (x$num_teeth_al_4mm >= 2 | x$num_teeth_pd_5mm >= 2) {
    return("Moderate")
  }
  if (x$num_al_3mm >= 2 & (x$num_teeth_pd_4mm >= 2 | x$max_pd >= 5)) {
    return("Mild")
  }
  return("No")
}

1st Problem:

Based on this classification,

  • "num_teeth_al_4mm >=" also includes all that are "num_teeth_al_6mm >=", and
  • "num_al_3mm >=" also includes all that are "num_teeth_al_4mm >=" and "num_teeth_al_6mm >=".

2nd Problem:

  • There are 4 measurements for "al" and "pd" per tooth and only the deepest measurement is valid. So to say, if the 4 measurements are as follows: 3 6 5 3 -> we would classify this tooth as 6 mm and above. So this particular tooth shouldn't be classified under "num_teeth_al_4mm >=" or "num_al_3mm >=".

The same issue goes for "num_teeth_pd_5mm >=" and "num_teeth_pd_4mm >="

This is how I coded these - perhaps the problem is here:

calcNumGt <- function(x, col.name, min_value) {
  sum(unlist(x[x[[col.name]]]) >= min_value)
}

calcNumTeethGt <- function(x, col.name, min_value) {
  tooth <- as.numeric(substr(x[[col.name]], 4, 5))
  d <- data.frame(probe=x[[col.name]], tooth=tooth, pd=unlist(x[x[[col.name]]]))
  max_pd_per_tooth <- aggregate(d$pd, list(d$tooth), max)
  sum(max_pd_per_tooth[2] >= min_value)
}


mydata$num_al_3mm <- apply(mydata, 1, calcNumGt, "interp_al_names", 3)
mydata$num_teeth_al_4mm <- apply(mydata, 1, calcNumTeethGt, "interp_al_names", 4)
mydata$num_teeth_al_6mm <- apply(mydata, 1, calcNumTeethGt, "interp_al_names", 6)

mydata$num_teeth_pd_4mm <- apply(mydata, 1, calcNumTeethGt, "interp_pd_names", 4)
mydata$num_teeth_pd_5mm <- apply(mydata, 1, calcNumTeethGt, "interp_pd_names", 5)

Please help me, I am not sure how to speficy these in the code.

Many thanks!

CodePudding user response:

for your 1st Problem:
=> use 'else if' instead of 'if'.

I did not understand the 2nd problem though...

Samuel

  • Related