How does one set up logical functions?

5 messages
Open this post in threaded view
|

How does one set up logical functions?

 Hi all, I am trying to set up logical function(s) to deal with two adjustments to a blood glucose value. I have been dinking around in Excel and assume this will be much easier in R. DF is date-time, BG value in mg/dL,test strip 4/3/13 19:20 105 Aviva-491350 4/4/13 21:03 74 Aviva-491350 4/6/13 17:40 81 Aviva-491640 4/6/13 17:40 82 Aviva-491350 4/6/13 22:48 106 Aviva-491640 4/6/13 22:48 102 Aviva-491350 4/7/13 5:32 87 Aviva-491350 4/7/13 5:32 103 Aviva-491640 What I need are the high and low ranges based on "acceptable" standards of the measured values. The logical expressions need to be IF BG =>100 then "High limit" would = (BG+(BG*.15)) IF BG =>100 then "Low limit" would = (BG-(BG*.15)) and IF BG <100 then "High limit" would = (BG+15) IF BG <100 then "Low limit" would = (BG-15) The standards are written as: 95% of the individual glucose results shall fall within ±15 mg/dL of the reference results at glucose concentrations less than 100 mg/dL and within ±15% at glucose concentrations greater than or equal to 100 mg/dL. Then I need to plot the measured value and also show the high & low "acceptable" values. Thanks for any who respond. Bruce -- Bruce W. Miller, PhD. Neotropical bat risk assessments If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet Using acoustic sampling to map species distributions for >15 years. Providing Interactive identification keys to the vocal signatures of New World Bats For various project details see: https://sites.google.com/site/batsoundservices/        [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: How does one set up logical functions?

 Hello, See if the following is what you want. dat <- structure(list(DF = c("4/3/13 19:20", "4/4/13 21:03", "4/6/13 17:40", "4/6/13 17:40", "4/6/13 22:48", "4/6/13 22:48", "4/7/13 5:32", "4/7/13 5:32"), BG = c(105L, 74L, 81L, 82L, 106L, 102L, 87L, 103L), test_strip = c("Aviva-491350", "Aviva-491350", "Aviva-491640", "Aviva-491350", "Aviva-491640", "Aviva-491350", "Aviva-491350", "Aviva-491640")), .Names = c("DF", "BG", "test_strip"), class = "data.frame", row.names = c(NA, -8L)) idx <- dat\$DF < 100 HighLimit <- LowLimit <- numeric(nrow(dat)) HighLimit[idx] <- dat\$BG[idx] + 15 LowLimit[idx] <- dat\$BG[idx] - 15 HighLimit[!idx] <- dat\$BG[!idx] + dat\$BG[!idx]*0.15 LowLimit[!idx] <- dat\$BG[!idx] - dat\$BG[!idx]*0.15 x <- as.POSIXct(dat\$DF, format = "%m/%d/%y %H:%M") yl <- range(c(dat\$BG, HighLimit, LowLimit)) plot(x, dat\$BG, ylim = yl, type = "b") lines(x, HighLimit) lines(x, LowLimit) Hope this helps, Rui Barradas Em 07-05-2013 15:02, Neotropical bat risk assessments escreveu: > Hi all, > > I am trying to set up logical function(s) to deal with two adjustments > to a blood glucose value. > I have been dinking around in Excel and assume this will be much easier > in R. > > DF is date-time, BG value in mg/dL,test strip > 4/3/13 19:20 105 Aviva-491350 > 4/4/13 21:03 74 Aviva-491350 > 4/6/13 17:40 81 Aviva-491640 > 4/6/13 17:40 82 Aviva-491350 > 4/6/13 22:48 106 Aviva-491640 > 4/6/13 22:48 102 Aviva-491350 > 4/7/13 5:32 87 Aviva-491350 > 4/7/13 5:32 103 Aviva-491640 > > > What I need are the high and low ranges based on "acceptable" standards > of the measured values. > > The logical expressions need to be > IF BG =>100 then "High limit" would = (BG+(BG*.15)) > IF BG =>100 then "Low limit" would = (BG-(BG*.15)) > and > IF BG <100 then "High limit" would = (BG+15) > IF BG <100 then "Low limit" would = (BG-15) > > The standards are written as: 95% of the individual glucose results > shall fall within ±15 mg/dL of the reference results at glucose > concentrations less than 100 mg/dL and within ±15% at glucose > concentrations greater than or equal to 100 mg/dL. > > Then I need to plot the measured value and also show the high & low > "acceptable" values. > > Thanks for any who respond. > > Bruce > > > > > ______________________________________________ > [hidden email] mailing list > 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. > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: How does one set up logical functions?

 In reply to this post by Bat Dude Try this: > input <- read.table(text = "date time BG test + 4/3/13 19:20    105     Aviva-491350 + 4/4/13 21:03    74      Aviva-491350 + 4/6/13 17:40    81      Aviva-491640 + 4/6/13 17:40    82      Aviva-491350 + 4/6/13 22:48    106     Aviva-491640 + 4/6/13 22:48    102     Aviva-491350 + 4/7/13 5:32     87      Aviva-491350 + 4/7/13 5:32     103     Aviva-491640", as.is = TRUE, header = TRUE) > # set limits > input\$High <- ifelse(input\$BG >= 100 +                 , input\$BG * 1.15 +                 , input\$BG + 15 +                 ) > input\$Low <- ifelse(input\$BG >= 100 +                 , input\$BG * 0.85 +                 , input\$BG - 15 +                 ) > input     date  time  BG         test   High   Low 1 4/3/13 19:20 105 Aviva-491350 120.75 89.25 2 4/4/13 21:03  74 Aviva-491350  89.00 59.00 3 4/6/13 17:40  81 Aviva-491640  96.00 66.00 4 4/6/13 17:40  82 Aviva-491350  97.00 67.00 5 4/6/13 22:48 106 Aviva-491640 121.90 90.10 6 4/6/13 22:48 102 Aviva-491350 117.30 86.70 7 4/7/13  5:32  87 Aviva-491350 102.00 72.00 8 4/7/13  5:32 103 Aviva-491640 118.45 87.55 > On Tue, May 7, 2013 at 10:02 AM, Neotropical bat risk assessments < [hidden email]> wrote: > Hi all, > > I am trying to set up logical function(s) to deal with two adjustments > to a blood glucose value. > I have been dinking around in Excel and assume this will be much easier > in R. > > DF is date-time, BG value in mg/dL,test strip > 4/3/13 19:20    105     Aviva-491350 > 4/4/13 21:03    74      Aviva-491350 > 4/6/13 17:40    81      Aviva-491640 > 4/6/13 17:40    82      Aviva-491350 > 4/6/13 22:48    106     Aviva-491640 > 4/6/13 22:48    102     Aviva-491350 > 4/7/13 5:32     87      Aviva-491350 > 4/7/13 5:32     103     Aviva-491640 > > > What I need are the high and low ranges based on "acceptable" standards > of the measured values. > > The logical expressions need to be > IF BG =>100 then "High limit" would = (BG+(BG*.15)) > IF BG =>100 then "Low limit" would = (BG-(BG*.15)) > and > IF BG <100 then "High limit" would = (BG+15) > IF BG <100 then "Low limit" would = (BG-15) > > The standards are written as: 95% of the individual glucose results > shall fall within Ä15 mg/dL of the reference results at glucose > concentrations less than 100 mg/dL and within Ä15% at glucose > concentrations greater than or equal to 100 mg/dL. > > Then I need to plot the measured value and also show the high & low > "acceptable" values. > > Thanks for any who respond. > > Bruce > > > -- > Bruce W. Miller, PhD. > Neotropical bat risk assessments > > If we lose the bats, we may lose much of the tropical vegetation and the > lungs of the planet > > Using acoustic sampling to map species distributions for >15 years. > > Providing Interactive identification keys to the vocal signatures of New > World Bats > > For various project details see: > > https://sites.google.com/site/batsoundservices/> > >         [[alternative HTML version deleted]] > > > ______________________________________________ > [hidden email] mailing list > 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. > > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.