0

I'm trying to understand the with function in context of a glm function output from here

First, a simple data set

set.seed(101)
x.test <- runif(50,2,8)
y.test <- 0.5^(x.test)
df <- data.frame(x.test, y.test)

I want to fit the function of form y.test ~ lambda/(1+ aii*x.test) using the inverse link function in glm

g1 <- glm(y.test ~ x.test, family = gaussian(link = "inverse"))
coef(g1)

(Intercept) x.test
-10.884889 6.946893

s0 <- with(as.list(coef(g1)), 
      list(lambda = 1/`(Intercept)`, aii = x.test/`(Intercept)`))

This produces a single value for $aii: [1] -0.6382144

Why does the with function do that? Should aii not produce 50 values given that x.test is a vector containing 50 values?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Rspacer
  • 2,369
  • 1
  • 14
  • 40

1 Answers1

0

This is a bit confusing because x.test can be found in three different places:

  • as a variable in the global workspace (a vector)
  • as an element of df (a vector)
  • as an element of as.list(coef(g1)) (a single value giving the coefficient of x.test in the regression equation)

When with(as.list(coef(g1)), ...) is used, the third location is the one searched first.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453