Last chance! 50% off unlimited learning
Sale ends in
Fits an iterated weighted least squares model.
iwlsm(x, ...)# S3 method for formula
iwlsm(formula, data, weights, ses, ..., subset, na.action,
method = c("M", "MM", "model.frame"),
wt.method = c("inv.var", "case"),
model = TRUE, x.ret = TRUE, y.ret = FALSE, contrasts = NULL)
# S3 method for default
iwlsm(x, y, weights, ses, ..., w = rep(1/nrow(x), nrow(x)),
init = "ls", psi = psi.iwlsm,
scale.est = c("MAD", "Huber", "proposal 2"), k2 = 1.345,
method = c("M", "MM"), wt.method = c("inv.var", "case"),
maxit = 20, acc = 1e-4, test.vec = "resid", lqs.control = NULL)
psi.iwlsm(u, k, deriv = 0, w, sj2, hh)
An object of class "iwlsm"
inheriting from "lm"
.
Note that the df.residual
component is deliberately set to
NA
to avoid inappropriate estimation of the residual scale from
the residual mean square by "lm"
methods.
The additional components not in an lm
object are
the robust scale estimate used
the weights used in the IWLS process
the psi function with parameters substituted
the convergence criteria at each iteration
did the IWLS converge?
a working residual, weighted for "inv.var"
weights only.
a formula of the form y ~ x1 + x2 + ...
.
data frame from which variables specified in formula
are
preferentially to be taken.
a vector of prior weights for each case.
An index vector specifying the cases to be used in fitting.
Estimated variance of the responses. Will be paseed to
psi
as sj2
A function to specify the action to be taken if NA
s are found.
The ‘factory-fresh’ default action in R is
na.omit
, and can be changed by
options(na.action=)
.
a matrix or data frame containing the explanatory variables.
the response: a vector of length the number of rows of x
.
Must be "M". (argument not used here).
are the weights case weights (giving the relative importance of case, so a weight of 2 means there are two of these) or the inverse of the variances, so a weight of two means this error is half as variable? This will not work at present.
should the model frame be returned in the object?
should the model matrix be returned in the object?
should the response be returned in the object?
optional contrast specifications: se lm
.
(optional) initial down-weighting for each case. Will not work at present.
(optional) initial values for the coefficients OR a method to find
initial values OR the result of a fit with a coef
component. Known
methods are "ls"
(the default) for an initial least-squares fit
using weights w*weights
, and "lts"
for an unweighted
least-trimmed squares fit with 200 samples. Probably not functioning.
the psi function is specified by this argument. It must give
(possibly by name) a function g(x, ..., deriv, w)
that for
deriv=0
returns psi(x)/x and for deriv=1
returns
some value. Extra arguments may be passed in via ...
.
method of scale estimation: re-scaled MAD of the residuals (default)
or Huber"s proposal 2 (which can be selected by either "Huber"
or "proposal 2"
).
tuning constant used for Huber proposal 2 scale estimation.
the limit on the number of IWLS iterations.
the accuracy for the stopping criterion.
the stopping criterion is based on changes in this vector.
additional arguments to be passed to iwlsm.default
or to the psi
function.
An optional list of control values for lqs
.
numeric vector of evaluation points.
tuning constant. Not used.
0
or 1
: compute values of the psi function or of its
first derivative. (Latter not used).
Estimated variance of the responses
Diagonal values of the hat matrix
Ruth Ripley
This function is very slightly adapted from rlm
in
packages MASS
. It alternates between weighted
least squares and estimation of variance on the basis of a common
variance. The function psi.iwlsm
calculates the weights
for the next iteration. Used by siena08
to combine estimates
from different sienaFits
.
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer. See also https://www.stats.ox.ac.uk/~snijders/siena/
siena08
, sienaMeta
, sienaFit
if (FALSE) {
##not enough data here for a sensible example, but shows the idea.
myalgorithm <- sienaAlgorithmCreate(nsub=2, n3=100)
mynet1 <- sienaDependent(array(c(s501, s502), dim=c(50, 50, 2)))
mynet2 <- sienaDependent(array(c(s502, s503), dim=c(50, 50, 2)))
mydata1 <- sienaDataCreate(mynet1)
mydata2 <- sienaDataCreate(mynet2)
myeff1 <- getEffects(mydata1)
myeff2 <- getEffects(mydata2)
myeff1 <- setEffect(myeff1, transTrip, fix=TRUE, test=TRUE)
myeff2 <- setEffect(myeff2, transTrip, fix=TRUE, test=TRUE)
myeff1 <- setEffect(myeff1, cycle3, fix=TRUE, test=TRUE)
myeff2 <- setEffect(myeff2, cycle3, fix=TRUE, test=TRUE)
ans1 <- siena07(myalgorithm, data=mydata1, effects=myeff1, batch=TRUE)
ans2 <- siena07(myalgorithm, data=mydata2, effects=myeff2, batch=TRUE)
meta <- siena08(ans1, ans2)
metadf <- split(meta$thetadf, meta$thetadf$effects)[[1]]
metalm <- iwlsm(theta ~ tconv, metadf, ses=se^2)
}
Run the code above in your browser using DataLab