-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working: co,sx,dx,pi,pwa,ri,mx,prx and cvr
Next action: TFA, ARI and CPPopt
- Loading branch information
Showing
5 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ export(cm_prx) | |
export(cm_pwa) | ||
export(cm_ri) | ||
export(cm_cvr) | ||
export(cm_co) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters