R programming: Using varfun to specify variance function in glm family quasi

StackOverflow https://stackoverflow.com/questions/5375021

  •  28-10-2019
  •  | 
  •  

Pergunta

I want to use varfun to specify my own variance functions in glm's quasi family, but I can't find any documentation on how to use the function. Does anyone have an idea on how to use this function?

Foi útil?

Solução

As it's set up, quasi() only takes its own pre-defined variance functions, which are "mu(1-mu)", "mu", "mu^2", "mu^3" and "constant". If you want to use one of those, you just have to specify it as a string to the variance = argument.

If you want to specify a variance function of your own: "The quasi family will accept the literal character string (or unquoted as a name/expression) specifications "constant", "mu(1-mu)", "mu", "mu^2" and "mu^3", a length-one character vector taking one of those values, or a list containing components varfun, validmu, dev.resids, initialize and name."

That's from the help file! How did I miss that before? Anyway, it might still be useful to look at the quasi function itself to see how it specifies each of those components for its pre-set variance functions.

If you want to specify a variance function of your own creation, you need to look at what the quasi() function returns:

structure(list(family = "quasi", link = linktemp, linkfun = stats$linkfun,
          linkinv = stats$linkinv, variance = varfun, dev.resids = dev.resids, 
          aic = aic, mu.eta = stats$mu.eta, initialize = initialize, 
          validmu = validmu, valideta = stats$valideta, varfun = variance_nm), 
          class = "family")

If you type quasi into the console (without parentheses), you can see how that function goes about creating this structure. You can create basically whatever "family" you'd like by modifying this structure and passing it to your glm()'s family = argument. Actually creating a new family that works as desired is way out of my depth, but this is how'd you do it. Caveat lector.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top