Displaying 20 results from an estimated 50000 matches similar to: "question on formula and terms.formula()"
2013 Jan 29
3
how to suppress the intercept in an lm()-like formula method?
I'm trying to write a formula method for canonical correlation analysis,
that could be called similarly to lm() for
a multivariate response:
cancor(cbind(y1,y2,y3) ~ x1+x2+x3+x4, data=, ...)
or perhaps more naturally,
cancor(cbind(y1,y2,y3) ~ cbind(x1,x2,x3,x4), data=, ...)
I've adapted the code from lm() to my case, but in this situation, it
doesn't make sense to
include an
2005 Jan 11
2
getting variable names from formula
R-list,
1. Given a formula (f) w variables referencing some data set (dat), is
there any easier/faster way than this to get the names (in character form)
of the variables on the RHS of '~' ?
dat <- data.frame(x1 = x1 <- rnorm(100,0,1), x2 = x2 <- rnorm(100,0,1), y = x1 + x2 + rnorm(100,0,1))
f <- y ~ x1 + x2
mf <- model.frame(f, data=dat)
mt <- attr(mf,
2011 Feb 21
2
Anomaly in [.terms
This arose when working on an addition to coxph, which has the features
that the X matrix never has an intercept column, and we remove strata()
terms before computing an X matrix. The surprise: when a terms object
is subset the intercept attribute is turned back on.
My lines 2 and 3 below were being executed just before a call to
model.frame. The simple solution was of course to do them in the
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 Aug 03
2
rnorm is not truly random used in the lm function
To whom it may concern,
I happened to run the following R code just to check the layout of the
output, but found that the code doesn't work the way I thought it should
work.
''
> lm(rnorm(100) ~ rnorm(100))
Call:
lm(formula = rnorm(100) ~ rnorm(100))
Coefficients:
(Intercept)
-0.07966
Warning messages:
1: In model.matrix.default(mt, mf, contrasts) :
the response appeared
2001 Aug 22
1
limited formula length in tsls
Dear all,
Using the tsls package, I noticed that regression lists longer
than 64 character
are getting truncated. Looking at the original source,
tsls.formula <- function(model, instruments, data, subset, weights,
na.action, contrasts=NULL){
if (missing(na.action))
na.action <- options()$na.action
m <- match.call(expand.dots = FALSE)
if (is.matrix(eval(m$data,
2005 Mar 29
1
improved pairs.formula?
Dear all,
I would like to suggest changing the pairs.formula command such that a
command like
pairs(GNP ~ . - Year - GNP.deflator, longley)
would behave in a similar fashion as
lm(GNP ~ . - Year - GNP.deflator, longley)
i.e., make a pairwise scatterplot of GNP and all other variables in
the (longley) dataframe except for Year and GNP.deflator. The above
command, with the
2004 Aug 28
6
model.matrix.default chokes on backquote (PR#7202)
Full_Name: Gabor Grothendieck
Version: R version 1.9.1, 2004-08-03
OS: Windows XP
Submission from: (NULL) (207.35.143.52)
The following gives an error:
> `a(b)` <- 1:4
> `c(d)` <- (1:4)^2
> lm(`a(b)` ~ `c(d)`)
Error in model.matrix.default(mt, mf, contrasts) :
model frame and formula mismatch in model.matrix()
To fix it replace this line in model.matrix.default:
2012 Jan 05
1
delete.response leaves response in attribute dataClasses
I posted this one as an R bug
(https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14767), but
Prof. Ripley says I'm premature, and I should raise the question here.
Here's the behavior I assert is a bug:
The output from delete.response on a terms object alters the formula
by removing the dependent variable. It removes the response from the
"variables" attribute and it changes
2004 Nov 08
1
plotting lm coeficients with their means
I am trying to write a function that will run a linear
model and plot the regression coeficients with their
corresponding means. I am having two problems. I can
get the plot with the function below, but I am having
trouble labeling the points.
function(y,x1,x2,x3,x4){
outlm<-lm(y~x1+x2+x3+x4)
imp<-as.data.frame(outlm$coef[-1])
meanvec<-c(mean(x1),mean(x2),mean(x3),mean(x4))
2003 Mar 10
4
terms.formula
I'm in the very initial stage of expanding the formula processing
in my quantile regression function rq() to handle additive
nonparametric components, say qss(x), or qss(x,z). I need some
advice about strategy for formula processing. My initial foray
was to use:
terms(formula,specials="qss")
and then modify the components of the resulting
terms.object. But in changing formula
2006 Mar 23
2
invalid variable type in model.frame within a function
Dear expeRts,
I came across the following error in using model.frame:
# make a data.frame
jet=data.frame(y=rnorm(10),x1=rnorm(10),x2=rnorm(10),rvar=rnorm(10))
# spec of formula
mf1=y~x1+x2
# make the model.frame
mf=model.frame(formula=mf1,data=jet,weights=rvar)
Which gives the desired output:
> mf
y x1 x2 (weights)
1 0.8041254 0.1815366 0.4999551 1.4957814
2
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
2013 Apr 12
2
model frame and formula mismatch in model.matrix()
Hello everyone,
I am trying to fit the following model
All X. variables are continuous, while the conditions are categoricals.
model <- lm(X2
2012 Jan 27
2
Why does the order of terms in a formula translate into different models/ model matrices?
Dear all,
I have encountered some strange things when creating lm objects in R: model
depends on the order of the terms specified in a formula.
Let us consider the following simple example:
> dat <- expand.grid(A = factor(c("a1", "a2")),
+ B = factor(paste("b", 1:4, sep="")),
+ rep = factor(1:2))
>
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 <-
2006 Sep 15
1
Formula aruguments with NLS and model.frame()
I could use some help understanding how nls parses the formula argument
to a model.frame and estimates the model. I am trying to utilize the
functionality of the nls formula argument to modify garchFit() to handle
other variables in the mean equation besides just an arma(u,v)
specification.
My nonlinear model is
y<-nls(t~a*sin(w*2*pi/365*id+p)+b*id+int,data=t1,
2012 Apr 20
1
predictOMatic for regression. Please try and advise me
I'm pasting below a working R file featuring a function I'd like to polish up.
I'm teaching regression this semester and every time I come to
something that is very difficult to explain in class, I try to
simplify it by writing an R function (eventually into my package
"rockchalk"). Students have a difficult time with predict and newdata
objects, so right now I'm
2010 Apr 21
2
Sparseby Problems
I've got a problem with the sparseby command (reshape library), and I have
reached the peak of my R knowledge (it isn't really that high).
I have a small data frame of 23 rows and 15 columns, here is a subset, the
first four columns are factors and the rest are numeric (only one, line54 is
provided).
bearID YEAR Season SEX line54
5 1900 8 3 0 16.3923519
11 2270
2005 Jan 24
2
using eval() with pre-built expression inside function
I'm trying to evaluate a pre-built expression using eval(), e.g.
dataset <- data.frame(y = runif(30, 50,100), x = gl(5, 6))
# one like this
mf <- expression(model.frame(y~x))
eval(mf, dataset, parent.frame())
# rather than this
eval(expression(model.frame(y~x)), dataset, parent.frame())
In the example above there is no problem, the problem comes when I try to do a similar thing