Skip to content

Commit

Permalink
Working: co,sx,dx,pi,pwa,ri,mx,prx and cvr
Browse files Browse the repository at this point in the history
Next action: TFA, ARI and CPPopt
  • Loading branch information
lilleoel committed Jul 24, 2020
1 parent a9ef170 commit 789768f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 4 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export(cm_prx)
export(cm_pwa)
export(cm_ri)
export(cm_cvr)
export(cm_co)
38 changes: 34 additions & 4 deletions R/cm_co.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
#Co - https ://www.ncbi.nlm.nih.gov/ pmc / articles /PMC5317099/
# CO (EST) = PP / (SBP+DBP) * HR
globalVariables(c("block","epoch","n","period","overlapping"))

cm_co <- function() {
print("Hello, world!")
cm_co <- function(
#Dataframes
df, del_1 = NULL, del_2 = NULL, trigger = NULL,
#Calculation settings
blocksize = 3, freq = 1000,
#Data Quality
blockmin = 0.5,
#Output
output = "period"
){
df_cols <- colnames(df)

#Global functions
z_validation(df, "recording", 3)
z_validation(del_1, "first deleter", 2)
z_validation(del_2, "second deleter", 2)
z_validation(trigger, "trigger", 2)

colnames(df) <- c("time","val1","val2")
df$n <- c(1:nrow(df))

df <- z_trigger(df,trigger)
df <- z_deleter(df,del_1)
df <- z_deleter(df,del_2)
df <- z_blocks(df,freq,blocksize)

df_agg <- z_agg(df,freq,blocksize,blockmin,by_type=c("max","min","mean"),n_vars=2)

results <- cm_co_output(df, df_agg, by_type=c("val1_max","val1_min","val2_mean"),freq, blocksize, output)

#FUNCTIONS ----
return(results)
}

46 changes: 46 additions & 0 deletions R/z_functions_co.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Output creation
cm_co_output <- function(df, df_agg, by_type, freq, blocksize, output){
if(output == "period"){

results <- NULL
for(i in unique(df_agg$period)){

temp <- cbind(i,
length(unique(df_agg$block[df_agg$period == i])),
min(df$time[df$period == i]),
max(df$time[df$period == i]),
mean(df_agg[df_agg$period == i,c(by_type[1])]),
mean(df_agg[df_agg$period == i,c(by_type[2])]),
mean(df_agg[df_agg$period == i,c(by_type[3])]),
mean(df_agg[df_agg$period == i,c(by_type[4])]),
round(100-sum(df_agg$length[df_agg$period == i])/
(freq*(max(df$time[df$period == i])-
min(df$time[df$period == i])))*100, digits=1),
mean((df_agg[df_agg$period == i,c(by_type[1])]-df_agg[df_agg$period == i,c(by_type[2])])/
(df_agg[df_agg$period == i,c(by_type[1])]+df_agg[df_agg$period == i,c(by_type[2])])*
df_agg[df_agg$period == i,c(by_type[3])])
)
results <- rbind(results,temp)

}

}else if(output == "block"){
results <- NULL
for(i in c(1:nrow(df_agg))){
temp <- cbind(df_agg[i,c("period","block")],
min(df$time[df$period == df_agg$period[i] & df$block == df_agg$block[i]]),
max(df$time[df$period == df_agg$period[i] & df$block == df_agg$block[i]]),
df_agg[i,c("val1_max","val1_min")],
round(100-df_agg$length[i]/(freq*blocksize)*100, digits=1),
(df_agg$val1_max[i]-df_agg$val1_min[i])/(df_agg$val1_max[i]+df_agg$val1_min[i])*
df_agg$val2_mean[i])
results <- rbind(results,temp)
}

}else{
stop("\'output\' must be left blank, 'period' or 'block'")
}
results <- as.data.frame(results)
colnames(results) <- c("period","blocks","time.min","time.max","val1_max","val1_min","val2_mean","missing.perc","cvr")
return(results)
}
27 changes: 27 additions & 0 deletions man/cm_co.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\name{cm_co}
\alias{cm_co}
\title{Cardiovascular resistance}
\description{
Calculates the co, and further described in following publication ...
[clinmon: An R package for calculation of clinical monitoring indices (2019)]
Co - https ://www.ncbi.nlm.nih.gov/ pmc / articles /PMC5317099/
CO (EST) = PP / (SBP+DBP) * HR
}
\usage{
cm_co(df, del_1, del_2, trigger, blocksize, freq, blockmin, output)
}
\arguments{
\item{df}{Data imported with 2 columns: time (in seconds), physiological measurement (raw measurement).}
\item{del_1}{Deleter periods for pressure with two columns, first column is start of deletion period and last column is end of deletion period, every row is a deletion period. (dataframe) }
\item{del_2}{Deleter periods for pressure with two columns, first column is start of deletion period and last column is end of deletion period, every row is a deletion period. (dataframe) }
\item{trigger}{Trigger periods with two columns, first column is start of analysed period and last column is end of analysed period, every row is a period for analysis. (dataframe)}
\item{blocksize}{Size of blocks created in seconds, default is 3 s. (numeric)}
\item{freq}{Frequency of recorded data, default is 1000 Hz. (numeric)}
\item{blockmin}{Minimum measurements ratio in every block, default is 0.5 (numeric)}
\item{output}{select the resolution of output, either 'period' or 'block' (boolian)}
}
\examples{
data <- data.frame(time=seq(7, 918, 0.001), pres=rnorm(911001),
hr=rnorm(911001))
cm_co(df=data)
}
2 changes: 2 additions & 0 deletions man/cm_cvr.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
\description{
Calculates the cvr, and further described in following publication ...
[clinmon: An R package for calculation of clinical monitoring indices (2019)]
Cvr formel - https://europepmc.org/article/pmc/pmc6054990
CVR = mean BP/mean MCAv
}
\usage{
cm_cvr(df, del_1, del_2, trigger, blocksize, freq, blockmin, output)
Expand Down

0 comments on commit 789768f

Please sign in to comment.