similar to: Playing with formulae

Displaying 20 results from an estimated 80000 matches similar to: "Playing with formulae"

2017 Mar 10
2
named arguments in formula and terms
Hi, we came across the following unexpected (for us) behavior in terms.formula: When determining whether a term is duplicated, only the order of the arguments in function calls seems to be checked but not their names. Thus the terms f(x, a = z) and f(x, b = z) are deemed to be duplicated and one of the terms is thus dropped. R> attr(terms(y ~ f(x, a = z) + f(x, b = z)),
2006 Jul 25
1
Follow Up To: Splitting the left and right hand terms of a formula
Hi All, I sent the following message to R-help on July 14th, 2006: Let's say I have the following formula: a.formula <- x ~ y + z I want to extract the left and right-hand sides of the function so that I have two character vectors like the ones you would create using the following assignments: left.hand.side <- "x" right.hand.side <- c("y", "z") One
2012 Jan 03
1
returning information from functions via attributes rather than return list
I would like to ask for advice from R experts about the benefits or dangers of using attr to return information with an object that is returned from a function. I have a feeling as though I have cheated by using attributes, and wonder if I've done something fishy. Maybe I mean to ask, where is the dividing line between attributes and instance variables? The separation is not clear in my mind
2011 Apr 19
1
How to Extract Information from SIMEX Output
Below is a SIMEX object that was generated with the "simex" function from the "simex" package applied to a logistic regression fit. From this mountain of information I would like to extract all of the values summarized in this line: .. ..$ variance.jackknife: num [1:5, 1:4] 1.684 1.144 0.85 0.624 0.519 ... Can someone suggest how to go about doing this? I can extract the
2006 Apr 11
1
Time Series information in formulae
Dear List The UKgas data is stored as an object of class 'ts'. I am trying to use "UKgas" in a formula as argument to a function. However, I do not know how to access the 'time series' information in the response (such as start() end() etc.). Here is a boiled down example. ssm <- function(formula, data = list(),subset=NULL) { cl <- match.call() if
2010 Jul 12
1
Checking formulae: are lower order terms included
Dear all, I have a very rudimental function which takes a vector of terms and returns a list of all possible models which can be made using the given terms. For example for the set c("1", "x", "y", "x:y") I'd get: ~ 1 ~ x ~ y ~ x:y ~ 1 + x ~ 1 + y ~ 1 + x:y ~ x + y ~ x + x:y ~ y + x:y ~ 1 + x + y ~ 1 + x + x:y ~ 1 + y + x:y ~ x + y + x:y ~ 1 + x + y +
2000 Oct 06
1
Formulae with factors that have missing values
Hi All, I have a formula which has a factor with NAs in it. I wish to keep these in the model matrix, but the NA information is currently lost (the rows are kept but the NA gets converted to 0). Any ideas as to how I can keep NAs in? e.g. junk <-
2010 Apr 06
2
Extracting formulae from expression() / deriv()
I am attempting to extract the derivative/ gradient from this expression df1p <- deriv(f1, "P") > df1p expression({ .value <- s - c - a * P .grad <- array(0, c(length(.value), 1L), list(NULL, c("P"))) .grad[, "P"] <- -a attr(.value, "gradient") <- .grad .value }) So in this case I want to extract the "-a".
2017 Nov 02
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
Hello Tyler, Thank you for searching for, and finding, the basic description of the behavior of R in this matter. I think your example is in agreement with the book. But let me first note the following. You write: "F_j refers to a factor (variable) in a model and not a categorical factor". However: "a factor is a vector object used to specify a discrete classification"
2004 Dec 13
3
Advice on parsing formulae
Dear list I would like to be able to group terms in a formula using a function that I will call tvar(), eg. the formula Y ~ 1 + tvar(x:A) + tvar(z) + u + tvar(B) + tvar(poly(v,3)) where x,u and v are numeric and A and B are factors - binary, say. As output, I want the model.matrix as if tvar had not been there at all. In addition, I would like to have information on the grouping, as a vector
2018 May 01
4
issue with model.frame()
A user sent me an example where coxph fails, and the root of the failure is a case where names(mf) is not equal to the term.labels attribute of the formula -- the latter has an extraneous newline. Here is an example that does not use the survival library. # first create a data set with many long names n <- 30? # number of rows for the dummy data set vname <- vector("character",
2017 Nov 04
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
Hello Tyler, I rephrase my previous mail, as follows: In your example, T_i = X1:X2:X3. Let F_j = X3. (The numerical variables X1 and X2 are not encoded at all.) Then T_{i(j)} = X1:X2, which in the example is dropped from the model. Hence the X3 in T_i must be encoded by dummy variables, as indeed it is. Arie On Thu, Nov 2, 2017 at 4:11 PM, Tyler <tylermw at gmail.com> wrote: > Hi
2003 Mar 26
2
predict (PR#2685)
There is a bug in `predict' whereby the order of variables sometimes gets re-arranged compared to the original fit, and then disaster results. Specifically, the 'variables' and 'predvars' attributes of a 'terms' object get out of synch. This only happens when the terms in the original formula get re-ordered during fitting: test> scrunge.data_ data.frame(
2008 Sep 24
2
Error message when calculating BIC
Hi All, Could someone help me decode what this error means ? > BIC(nb.80) Error in log(attr(object, "nobs")) : Non-numeric argument to mathematical function > BTW, nb.80 is a negative binomial glm model created using the MASS library with the call at the bottom of the message In the hopes of trying to figure this out I tried the following workaround but it did not work
2017 Oct 27
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
Hello Tyler, I want to bring to your attention the following document: "What happens if you omit the main effect in a regression model with an interaction?" (https://stats.idre.ucla.edu/stata/faq/what-happens-if-you-omit-the-main-effect-in-a-regression-model-with-an-interaction). This gives a useful review of the problem. Your example is Case 2: a continuous and a categorical regressor.
2017 Nov 06
2
Bug in model.matrix.default for higher-order interaction encoding when specific model terms are missing
Hello Tyler, You write that you understand what I am saying. However, I am now at loss about what exactly is the problem with the behavior of R. Here is a script which reproduces your experiments with three variables (excluding the full model): m=expand.grid(X1=c(1,-1),X2=c(1,-1),X3=c("A","B","C")) model.matrix(~(X1+X2+X3)^3-X1:X3,data=m)
2017 Dec 26
1
identifying convergence or non-convergence of mixed-effects regression model in lme4 from model output
Hi R community! I've fitted three mixed-effects regression models to a thousand bootstrap samples (case-resampling regression) using the lme4 package in a custom-built for-loop. The only output I saved were the inferential statistics for my fixed and random effects. I did not save any output related to the performance to the machine learning algorithm used to fit the models (REML=FALSE).
2009 Sep 06
1
How to refer the element in a named list?
Hi, I thought that 'coefficients' is a named list, but I can not refer to its element by something like r$coefficients$y. I used str() to check r. It says the following. Can somebody let me know what it means? ..- attr(*, "names")= chr [1:2] "(Intercept)" "y" $ Rscript lm.R > x=1:10 > y=1:10 > r=lm(x~y) > class(r) [1] "lm" >
2024 Sep 20
1
model.matrix() may be misleading for "lme" models
Dear r-devel list members, I'm posting this message here because it concerns the nlme package, which is maintained by R-core. The problem I'm about to describe is somewhere between a bug and a feature request, and so I thought it a good idea to ask here rather posting a bug report to the R bugzilla. I was made aware (by Ben Bolker) that the car::Anova() method for "lme"
2006 Jul 14
1
Splitting the left and right hand terms of a formula
Let's say I have the following formula: a.formula <- x ~ y + z I want to extract the left and right-hand sides of the function so that I have two character vectors like the ones you would create using the following assignments: left.hand.side <- "x" right.hand.side <- c("y", "z") One way to do this follows: left.hand.side <-