find_difference {itsadug} | R Documentation |
Return the regions in which the smooth is significantly different from zero.
Description
Return the regions in which the smooth is significantly different from zero.
Usage
find_difference(mean, se, xVals = NULL, f = 1, as.vector = FALSE)
Arguments
mean |
A vector with smooth predictions. |
se |
A vector with the standard error on the smooth predictions. |
xVals |
Optional vector with x values for the smooth.
When |
f |
A number to multiply the |
as.vector |
Logical: whether or not to return the data points as vector, or not. Default is FALSE, and a list with start and end points will be returned. |
Value
The function returns a list with start points of each region
(start
) and end points of each region (end
). The logical
xVals
indicates whether the returned values are on the x-scale
(TRUE) or indices (FALSE).
Author(s)
Jacolien van Rij
See Also
Other Utility functions:
convertNonAlphanumeric()
,
corfit()
,
diff_terms()
,
missing_est()
,
modeledf()
,
observations()
,
print_summary()
,
refLevels()
,
res_df()
,
summary_data()
,
timeBins()
Examples
data(simdat)
# Use aggregate to calculate mean and standard deviation per timestamp:
avg <- aggregate(simdat$Y, by=list(Time=simdat$Time),
function(x){c(mean=mean(x), sd=sd(x))})
head(avg)
# Note that column x has two values in each row:
head(avg$x)
head(avg$x[,1])
# Plot line and standard deviation:
emptyPlot(range(avg$Time), c(-20,20), h0=0)
plot_error(avg$Time, avg$x[,'mean'], avg$x[,'sd'],
shade=TRUE, lty=3, lwd=3)
# Show difference with 0:
x <- find_difference(avg$x[,'mean'], avg$x[,'sd'], xVals=avg$Time)
# Add arrows:
abline(v=c(x$start, x$end), lty=3, col='red')
arrows(x0=x$start, x1=x$end, y0=-5, y1=-5, code=3, length=.1, col='red')