Learn R Programming

bda (version 3.1.3-2)

weighting: To weight the data

Description

To create an R object by weighting the data with a vector of weights.

Usage

weighting(x,w,freq=FALSE,na.rm=TRUE, type, method,...)

Arguments

x
vector of observations from the distribution whose density is to be estimated. Missing values are not allowed.
w
The weights of x. The weight w_i of any observation x_i should be non-negative. If x_i=0, x_i will be removed from the analysis. For survival data, w is a vector of cen
freq
An indicator showing whether w is a vector of frequecies (counts) or weights.
na.rm
logical flag: if TRUE, NA values will be ignored; otherwise, the program will be halted with error information.
type
Data type: rc for random right-censoring. If missing, weighted by w.
method
method to compute the weights. Not needed if type is missing.
...
controls

Value

  • a list containing the following components:
  • xvector of sorted x values at which the estimate was computed.
  • yvector of weights estimates at the corresponding x.
  • nlength of x
  • sizesample size (of the original data).
  • totMasstotal mass. needed for data with censoring.
  • parsReserved.

encoding

UTF-8

References

Wang, B. and Wang, X-F. (2007). "Bandwidth Selection for Weighted Kernel Density Estimation".

See Also

lprde.

Examples

Run this code
## time to relapse of patients in a clinical trial of 6-MP 
 ## against a placebo (Survival Analysis, Klein and Moeschberger 
 ## (1950) 2nd edition). 

 x <- c(10,7,32,23,22,6,16,34,32,25,11,20,19,6,17,35,6,13,9,6,10)
 w <- c(1,1,0,1,1,1,1,0,0,0,0,0,0,1,0,0,1,1,0,0,0)
 (out1 <- weighting(x,w,type="rc",method="Nelson"))
 (out2 <- weighting(x,w,type="rc",method="Kaplan"))

Run the code above in your browser using DataLab