To Projects

Project 7

Goal: Implement the S3 class ChlorReads.  Here is the ChlorReads UML diagram.

Relevent Examples: Kid in the 5/18 Notes and Die

  1. Create a constructor ChlorReads that inputs the fields id, name, gender, ldl, hdl, and trigl and returns a ChlorReads object.
     
  2. Define a print.ChlorReads method that prints a ChlorReads object like this:
    * means high risk value, + means borderline.  Use these cutoff values the three chloresterol values:
    Type Range Meaning Symbol
    LDL 0 to 200 Normal ""
    LDL 200 to 240 Borderline "+"
    LDL 240 and up High Risk "*"
    HDL 0 to 40 High Risk "*"
    HDL 40 to 60 Borderline "+"
    HDL 60 and up Normal " "
    Trigl 0 to 150 Normal ""
    Trigl 150 to 200 Borderline "+"
    Trigl 200 and up High Risk "*"

    You can use an if-else statement to obtain the symbol. However, be careful not to start a new line with else:
  3. Define the method plot.ChlorReads that plots the data in the ChlorReads object like this:
     

     
  4. Define the accessor methods getPatientInfo.ChlorReads and getChloresterol.ChlorReads. First define the generic methods getPatientInfo and getCholesterol and the default methods getPatientInfo.default and getCholesterol.default. For example:
  5. Write an R script that does the following:
     
    1. Tests the methods defined in 1 through 4.
       
    2. Uses the data in chlor-reads.txt to create a list lst of ChlorReads objects indexed as [[1]], [[2]], ... , [[length(lst)]]. To do this, you can use a for loop to process the rows of the data frame:
        lst <- NULL
        chlor <- read.table("chlor-reads.txt")
        for(i in 1:nrow(chlor)) {
           lst[[i]] <- ChlorReads(chlor[i, ]$id, as.character(chlor[i, ]$name),
              as.character(chlor[i, ]$gender), chlor[i, ]$ldl,  
              chlor[i, ]$hdl, chlor[i, ]$trigl)
        }
        
      The as.character method calls for the name and gender components are because these components are stored as factor objects in a data frame.
       
    3. Uses a for loop to print all of the ChlorReads objects in lst.
       
    4. Uses a for loop to plot all of the ChlorReads objects in lst to a PDF file.