I am learning the propagate function and want to use it to calculate the propagated error of summing the raw data in a data frame column. Each row in the data frame is a record, provided with raw data and standard error. A total of one hundred rows (records) are in the data frame. I tried the below code, but it does not work. Can anyone help please!
library(propagate)
set.seed(1)
#create data frame with 100 records with random mean and se
df <- data.frame(raw.data= runif(n=100, min=20, max=100),
se = runif(n=100, min=1, max=10))
# set record name, each record is one term in the equation
for (i in 1:100){
rownames(df)[i]<- paste("x",i, sep="")
}
#transpose to the format required in propagate()
# first row is mean, second row is se
df<-t(df)
#get the equation
col <- paste (colnames(df), collapse="+")
EXPR <- expression(col) # so it should be x1+x2+x3+...+x100
RES1 <- propagate(expr = EXPR, data = df, type = "stat",
do.sim = TRUE, verbose = TRUE)
error message "Error in propagate(expr = EXPR, data = df, type = "stat", do.sim = TRUE, : propagate: variable names of input dataframe and expression do not match!"
Not familiar with this package, but looking at the documentation, I suspect that your main problem is that the
exprargument needs variables as inputs, but you are feeding it column names.The following produces a result...