its_loess: Estimates via Local Polynomial Regression

Description Usage Arguments Details Value See Also Examples

Description

its_loess estimates the intercept shift of a time series at a cut-point.

Usage

1
2
its_loess(df, rvar, outcome, span = 0.8, degree = 1, donut = 0,
  othervar = NULL, only_estimates = TRUE, na.action = "na.omit")

Arguments

df

(required) data.frame containing all variables

rvar

(required) the name of the running variable in df

outcome

(required) the name of the outcome variable in df

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 rvar).

othervar

vector of variable names that will be included into the returned data.frame (if only_estimate=FALSE).

na.action

parameter passed on to loess about how to handle missing values

only_estimate

if TRUE only returns the estimates at the cut-point (default)

Details

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').

Value

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.

See Also

loess.

Examples

 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)

sumtxt/itstools documentation built on May 30, 2019, 8:38 p.m.