What does the "weights" argument do when fitting Kaplan-Meier curveswith the survival package? In R's survival package, there is an optional weights argument you can supply when you fit a Kaplan-Meier curve. I can't find any documentation about what this does or what exactly a weighted Kaplan Meier estimate is.
I'm aware there are modification to Kaplan-Meier estimates for ties. For this question, any clarification about the basic estimator is fine,
$$ \hat{S}(t) = \prod_{i: \space  t_i \leq t} \bigg(1 - \frac{d_i}{n_i} \bigg) $$
How do weights change the Kaplan Meier estimate above? I don't see how a weight for every subject, $i$, could enter the model above.
If this were a model with iid observations and a well defined likelihood function, I would get parameter estimates by maximizing the log likelihood,
$$\theta^* = \arg\max\limits_\theta \sum_i w_i \log(\mathcal{L}(\theta|x_i)),$$
with a weight $w_i$ for every observation.  What is the analog for survival models, where terms in the likelihood are multiplied over the risk set?
Is there an interpretation in terms of $d_i$ and $n_i$ of how adding a weight, $w_i$, changes the Kaplan-Meier estimates

In the weighted version of the Kaplan-Meier estimator you replace the number of events $d_i$ at time $t_i$ by the sum of the weights for the individuals who had events at that time.  You replace the number at risk, $n_i$ by the sum of the weights for the individuals at risk.
The weights in the survival package are frequency weights; a weight of, say, 3 means the same as having 3 copies of that observation. If you gave every observation a weight of 3, you'd get the same point estimates, with standard errors that were $\sqrt{3}$ times smaller.  Frequency weights give the same point estimates as sampling weights, but the standard error estimates are quite different.
In the Cox model, the weights are again frequency weights. Again, it's like having that many copies of the observation.
If your weights are actually sampling weights, the ideal approach is to use the survey package. It calls the survival package for the parts of the computation that can be done the same way, but does the standard error estimation differently.
