Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that another offset is not specified #41

Open
dill opened this issue Aug 30, 2021 · 1 comment
Open

Check that another offset is not specified #41

dill opened this issue Aug 30, 2021 · 1 comment
Milestone

Comments

@dill
Copy link
Contributor

dill commented Aug 30, 2021

It's currently totally legal to write a dsm formula with an offset in it. This throws the following warning:

Warning message:
In av[kp] <- as.character(attr(tf, "variables")[1 + off]) :
  number of items to replace is not a multiple of replacement length

Usually the user will not want 2 offsets, so we should stop them doing this.

@dill dill added this to the 2.4.0 milestone Aug 30, 2021
@dill dill self-assigned this Aug 30, 2021
@dill
Copy link
Contributor Author

dill commented Nov 29, 2022

This can be checked using the terms function and looking at the resulting attributes:

> terms(formula(x~y + offset(a)))
x ~ y + offset(a)
attr(,"variables")
list(x, y, offset(a))
attr(,"offset")
[1] 3
attr(,"factors")
          y
x         0
y         1
offset(a) 0
attr(,"term.labels")
[1] "y"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>

so here attr(terms(formula(x~y + offset(a))), "offset") will give the position of the offset term. Whereas when there is no offset:

> terms(formula(x~y))
x ~ y
attr(,"variables")
list(x, y)
attr(,"factors")
  y
x 0
y 1
attr(,"term.labels")
[1] "y"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>

There is no offset attribute. So testing for presence of that attribute should be enough.

@dill dill removed their assignment Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant