data_polate: Linearly extrapolate/interpolate variables in a numeric...

View source: R/data_polate.R

data_polateR Documentation

Linearly extrapolate/interpolate variables in a numeric matrix

Description

Linearly extrapolate/interpolate variables in a numeric matrix data. This function uses Hmisc::approxExtrap() and base::apply() to extrapolate variables y_i to y_n in a data frame based on univariate relationships with a variable x (x; which is another variables in data) to a new variable xout.

Usage

data_polate(data, xname = NULL, ynames = NULL, xout = NULL)

Arguments

data

a numeric matrix or data frame that can be coerced to a numeric matrix with column names containing the x variable and y_i variables to extrapolate

xname

the name of the column containing the x variable. If is.null(xname) the first column will be used.

ynames

the names of the columns containing the y variables. If is.null(ynames) all column names other than xname are used.

xout

a numeric vector of values to x values to extrapolate y_i to. If if(is.null(xout)){xout <- x}, and the function doesn't extrapolate anything.

Note

Users should be cautious about conducting linear extrapolation for relationships that are known to be non-linear over a large range, because they will undoubtedly deviate from the true non-linear relationships. Linear interpolation will also deviate, though the risks will tend to be less severe especially if the resolution of the original data is relatively fine.

Author(s)

Nikolai Klibansky

Examples

## Not run: 
mydata <- rdat_RedGrouper$a.series
 out <- data_polate(mydata,xout=seq(min(mydata$age),max(mydata$age),by=0.5))
 par(mfrow=c(1,1))
for(i in colnames(out[,-1])){
 x <- mydata[,1]
 xout <- out[,1]
 yout_i <- out[,i]
 plot(xout,yout_i,ylab=i)
 points(x,mydata[,i],col="red",pch=16)
 readline(prompt="Press [enter] to continue")
}

## End(Not run)

nikolaifish/bamExtras documentation built on July 21, 2023, 8:26 a.m.