Description Usage Arguments Details Value See Also Examples
its_loess
estimates the intercept shift of a time series at a cut-point.
1 2 |
df |
(required) |
rvar |
(required) the name of the running variable in |
outcome |
(required) the name of the outcome variable in |
span |
either a scalar or a vector of length 2 for the span to be used to the left and right of the cut-point. |
degree |
either a scalar or a vector of length 2 defining the degree of the polynomial to the left and right of the cut-point. |
donut |
either a scalar or a vector of length 2 defining the length of the period to the left (right) of the cut-point for which the data are dropped (on the scale of |
othervar |
vector of variable names that will be included into the returned |
na.action |
parameter passed on to |
only_estimate |
if |
This function estimates two local polynomial regressions via loess
to the left and
right of the cut-point at zero. The predicted values from the regressions are used to form an
estimate of the intercept shift at the cut-point. The reported t-statistic and p-value is based
on a standard Welch's t-test with unequal variances.
As span increases, the regression becomes a linear regression with a linear (degree=1) or quadratic trend term (degree=2).
The loess parameters are set such that the surface and statistics are computed exactly, i.e. loess.control(surface='direct', statistics='exact')
.
If only_estimate=TRUE
a data.frame
with a single row and entries for the point estimate of the intercept shift (diff.est
),
standard error (diff.se
), t-statistic (diff.tstat
), p-value (diff.pval
) as well as the degree and span used in the
estimation. If only_estimate=FALSE
, a data.frame
that contains the variables as named in rvar,outcome,othervar
as
well as the predicted values (yhat*
), standard errors (yhat*.se
) and upper/lower bound of the 95% confidence interval (based on a normal distribution)
(yhat*.lo
,yhat*hi
) from the loess
regressions to the left (*=0) and to the
right (*=1) of the cut-point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## Not run:
eventmonth <- -12:12
treat <- as.numeric(eventmonth >= 0)
y <- 1 + (1 * eventmonth) + treat*10 + rnorm(length(eventmonth))
df <- data.frame(y=y, eventmonth=eventmonth)
its_loess(df, rvar="eventmonth", outcome="y")
m <- its_loess(df, rvar="eventmonth", outcome="y", only_estimate=FALSE)
with(m, plot(eventmonth, y))
with(m, lines(eventmonth, yhat0, col='blue'))
with(m, lines(eventmonth, yhat1, col='blue'))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.