I'm new to coding in R and am having a difficult time coding the following equation
142 x (Scr/A)^B x 0.9938^age x (1.012 if female)
Female
- Scr <=0.7; A = 0.7, B = -0.241
- Scr >0.7; A = 0.7, B = -1.2
Male
- Scr <=0.9; A = 0.9, B = -0.302
- Scr >0.9; A = 0.9, B = -1.2
(There is an existing R package for the old version of this equation, but not this updated one).
Could someone help me with the code? Having a hard time figuring out how to create a new variable (eGFR) with values calculated from this equation. The components A and B of the equation depend on 2 categories of variable Scr (serum creatinine) and on gender (M/F). Thanks!
wave1.data$baseline.egfr <- (if(wave1.data$Sex=="Male") {M1 <- wave1.data$Creatinine >= 0.9
M2 <- wave1.data$Creatinine < 0.9
eGFR <- (142*(wave1.data$Creatinine/A1)^-0.302*(0.9938^wave1.data$Age))
eGFR <- (142*(wave1.data$Creatinine/A2)^-1.2*(0.9938^wave1.data$Age))}
else if(wave1.data$Sex=="Female")
{F1 <- wave1.data$Creatinine >= 0.7
F2 <- wave1.data$Creatinine < 0.7
eGFR <- (142*(wave1.data$Creatinine/A1)^-0.241*(0.9938^wave1.data$Age))
eGFR <- (142*(wave1.data$Creatinine/A2)^-1.2*(0.9938^wave1.data$Age))})