I am trying to run separate regressions for different groups of
observations using the lapply function. It works fine when I write the
formula inside the lm() function. But I would like to pass formulae into
lm(), so I can do multiple models more easily. I got an error message
when I tried to do
try this:
lapply(levels(df$group), function(x)lm(formula1, data=df[group==x,]))
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O
On 15/08/07, Li, Yan (IED) [EMAIL PROTECTED] wrote:
I am trying to run separate regressions for different groups of
observations using the
It can't find x since the environment of formula1 and of formula2 is the Global
Environment and x is not there -- its local to the function.
Try this:
#generating data
set.seed(1)
DF - data.frame(y = rnorm(100, 1), x1 = rnorm(100, 1), x2 = rnorm(100, 1),
group = rep(c(A, B), c(40, 60)))
try this:
x = predict(z, Iris[-train, ])
x1 - rnorm(100,1)
x2 - rnorm(100,1)
y - rnorm(100,1)
group - rep(c(A,B),c(40,60))
group - factor(group)
df - data.frame(y,x1,x2,group)
resf1 - lapply(levels(df$group),function(x) {formula1 - as.formula(y~x1);
lm(formula1,df, subset =group ==x)})
Here is another solution that gets around the non-standard
way that subset= is handled in lm. It has the advantage that unlike
the previous solution where formula1 and group == x appear literally
in the output, in this one the formula appears written out and
group == A and group == B appear:
Isaac Kohane wrote:
Forgive me if this is obvious:
I have a frame of data with the variables in each column (e.g.
Discrete_Variable1, ContinuousVariable_1, ContinuousVariable_2, ...
ContinuousVariable_n)
and I want to create a model using lrm i.e.
model -
Forgive me if this is obvious:
I have a frame of data with the variables in each column (e.g.
Discrete_Variable1, ContinuousVariable_1, ContinuousVariable_2, ...
ContinuousVariable_n)
and I want to create a model using lrm i.e.
model - lrm(Discrete_Variable1 ~
I have an object, ARestopt, that is the result of a call to the arima
function. I want to calculate test statistics ( null is coeffs are zero
) for each of the estimated coefficients.
My coefficents are in a vector called ARestopt$coef and my covariance
matrix is ARestopt$var.coef.
I thought
Hello, I am trying to input the following formula into R for parameter
estimation. I don't quite have the just of formula syntax. I understand
simple basic regression (y ~ x), but how do I do the ff:
y = ( b0*x )/(x + b1),
where b0 and b1 are parameters that need to be solved. Any
I haven't seen any replies to this post, so I will offer a couple
of comments.
First, your example is entirely too complicated and not self
contained for me to say much in the limited time I have for this. I
suggest you start by splitting your problem into several steps. For
Spencer,
Thank you for taking time to reply and offer suggestions. garchFit does
not allow 'formula.mean=~z+arma(p, q)', nor does it allow xreg=(x,y)
options. Any thing is xreg is ignored with a warming or error.
I have debugged garchFit and I know where the code should be modified to
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
Good Day: When I used:
multinom(formula = Y ~ X1 + X2 + X3 + X1:X2 + X1:X3 + X3:X2 + X1^2 + X2^2 +
X3^2, data = DATASET),
I get estimates and AIC for the model containing main effects and
interactions only (no squared terms)...and FYI, all predictors are
continuous. Is this normal behavior? If I
:33 AM
To: 'r-help@stat.math.ethz.ch'
Subject: [R] formula restriction in multinom?
Good Day: When I used:
multinom(formula = Y ~ X1 + X2 + X3 + X1:X2 + X1:X3 + X3:X2 +
X1^2 + X2^2 +
X3^2, data = DATASET),
I get estimates and AIC for the model containing main effects and
interactions only
weihong wrote:
Can GLMM take formula derived from another object?
foo - glm (OVEN ~ h + h2, poisson, dataset)
# ok
bar - GLMM (OVEN ~ h + h2, poisson, dataset, random = list (yr = ~1))
#error
bar - GLMM (foo$formula, poisson, dataset, random = list (yr = ~1))
#Error in foo$(formula +
On Mon, 2005-05-02, 17:24, Douglas Bates wrote:
weihong wrote:
Can GLMM take formula derived from another object?
foo - glm (OVEN ~ h + h2, poisson, dataset)
# ok
bar - GLMM (OVEN ~ h + h2, poisson, dataset, random = list (yr = ~1))
#error
bar - GLMM (foo$formula, poisson, dataset,
Henric Nilsson wrote:
On Mon, 2005-05-02, 17:24, Douglas Bates wrote:
weihong wrote:
Can GLMM take formula derived from another object?
foo - glm (OVEN ~ h + h2, poisson, dataset)
# ok
bar - GLMM (OVEN ~ h + h2, poisson, dataset, random = list (yr = ~1))
#error
bar - GLMM (foo$formula,
From: Douglas Bates
Henric Nilsson wrote:
On Mon, 2005-05-02, 17:24, Douglas Bates wrote:
weihong wrote:
Can GLMM take formula derived from another object?
foo - glm (OVEN ~ h + h2, poisson, dataset)
# ok
bar - GLMM (OVEN ~ h + h2, poisson, dataset, random =
list (yr =
Can GLMM take formula derived from another object?
foo - glm (OVEN ~ h + h2, poisson, dataset)
# ok
bar - GLMM (OVEN ~ h + h2, poisson, dataset, random = list (yr = ~1))
#error
bar - GLMM (foo$formula, poisson, dataset, random = list (yr = ~1))
#Error in foo$(formula + yr + 1) : invalid
Hi all,
Perhaps somebody can explain the following behaviour to me.
Take the following data.frame.
z - expand.grid(X = LETTERS[1:3], Y = letters[1:3])
Now, from ?formula we see:
quote
The '*' operator denotes factor crossing: 'a*b' interpreted as 'a+b+a:b'.
/quote
So I would expect the following:
See MASS4 pp.149-150 (and I don't know of a similarly detailed explanation
elsewhere, although there is a terser account in the White Book).
On Fri, 11 Feb 2005, Sundar Dorai-Raj wrote:
Hi all,
Perhaps somebody can explain the following behaviour to me.
Take the following data.frame.
z -
Hallo
On 15 Jul 2004 at 13:46, [EMAIL PROTECTED] wrote:
Hi, don' t understand why the function fomula have this error, i
enclose the parameter a with the function I() Thank Ruben
x-1:5
y-c( 2 ,4 , 6 , 8 ,11)
formu-y~I(a*x)
form-formula(formu)
dummy-data.frame(x=x,y=y)
Hi, i 'dont understand how to take a general formula, view this:
x-1:5
y-c(0,1,1.7,2,2.1.4)
dummy-data.frame(x=x,y=y)
formula-y~A*log(x)/log(2)
formu-as.formula(formula)
fm-lm(formu,data=dummy)
Error in eval(expr, envir, enclos) : Object A not found
but A is the parameter of fitting, why is
The '*' operator denotes factor crossing: 'a*b'
interpreted as 'a+b+a:b'
read ? formula.
Best
Vito
Hi, i 'dont understand how to take a general formula,
view this:
x-1:5
y-c(0,1,1.7,2,2.1.4)
dummy-data.frame(x=x,y=y)
formula-y~A*log(x)/log(2)
formu-as.formula(formula)
fm-lm(formu,data=dummy)
On Thu, 2004-07-15 at 16:28, [EMAIL PROTECTED] wrote:
Hi, i 'dont understand how to take a general formula, view this:
x-1:5
y-c(0,1,1.7,2,2.1.4)
dummy-data.frame(x=x,y=y)
formula-y~A*log(x)/log(2)
formu-as.formula(formula)
fm-lm(formu,data=dummy)
You probably meant something similar to
If you want to fit y = a + bx, then you use lm(y ~ x) instead of lm(y ~ A + bx).
See the details section of help(formula).
x - 1:5
y - c(0, 1.0, 1.7, 2.0, 2.1)
lm(x ~ y)
Call:
lm(formula = x ~ y)
Coefficients:
(Intercept)y
0.6828 1.7038
PS : I think there is a typo
If you want to fit y = a + bx, then you use lm(y ~ x) instead of lm(y ~ A + bx).
See the details section of help(formula).
x - 1:5
y - c(0, 1.0, 1.7, 2.0, 2.1)
lm(x ~ y)
Call:
lm(formula = x ~ y)
Coefficients:
(Intercept)y
0.6828 1.7038
If A was already defined, and
If you want to fit y = a + bx, then you use lm(y ~ x) instead of lm(y ~ A + bx).
'A' is not a parameter but coefficient and you do not need to specify coefficients,
which is what the linear model is trying to do anyway !
See the details section of help(formula).
x - 1:5
y - c(0, 1.0, 1.7,
Hi, don' t understand why the function fomula have this error, i enclose
the parameter a with the function I()
Thank Ruben
x-1:5
y-c( 2 ,4 , 6 , 8 ,11)
formu-y~I(a*x)
form-formula(formu)
dummy-data.frame(x=x,y=y)
fm-lm(form,data=dummy)
Error in unique(c(AsIs, oldClass(x))) : Object a not found
It wants to compute a*x given a and x, and then use ordinarly least
squares to estimate b0 and b1 in y = b0 + b1*I(a*x). If that is what
you intend, you must supply a. If you want to estimate a, e.g., with no
constant, use y~x-1. Does this answer the question? hope this
helps. spencer
Xiaorong Chen wrote:
Dear Sir or Madam,
What is the formula for power.t.test(delta=delta, sd=segma, sig.level=0.05,
power=0.8, type=one.sample, alternative=one.sided)$n?
See the code of power.t.test by just typing the name of that function
into the console:
power.t.test
and you'll easily
Dear Sir or Madam,
What is the formula for power.t.test(delta=delta, sd=segma, sig.level=0.05,
power=0.8, type=one.sample, alternative=one.sided)$n?
Thank you very much for the help!
Best,
Xiaorong
__
[EMAIL PROTECTED] mailing list
Russell Senior wrote:
I am writing a little abstraction for a series of tests. For example,
I am running an anova and kruskal.test on a one-factor model. That
isn't a particular problem, I have an interface like:
my.function - function(model,data) {
print(deparse(substitute(data)))
a -
Uwe == Uwe Ligges [EMAIL PROTECTED] writes:
Russell I am writing a little abstraction for a series of tests. For
Russell example, I am running an anova and kruskal.test on a
Russell one-factor model. That isn't a particular problem, I have an
Russell interface like: my.function -
Uwe == Uwe Ligges [EMAIL PROTECTED] writes:
Russell I am writing a little abstraction for a series of tests. For
Russell example, I am running an anova and kruskal.test on a
Russell one-factor model. That isn't a particular problem, I have an
Russell interface like: my.function -
Russell Senior wrote:
Uwe == Uwe Ligges [EMAIL PROTECTED] writes:
Russell I am writing a little abstraction for a series of tests. For
Russell example, I am running an anova and kruskal.test on a
Russell one-factor model. That isn't a particular problem, I have an
Russell interface like:
Uwe == Uwe Ligges [EMAIL PROTECTED] writes:
Russell Suppose I want x to be log(Ozone)? The get() function
Russell doesn't help me there.
Uwe eval(parse(text=x))
Ah, that seems to have done it. Thanks!
--
Russell Senior ``I have nine fingers; you have ten.''
[EMAIL PROTECTED]
On Tue, 28 Oct 2003, Russell Senior wrote:
Uwe == Uwe Ligges [EMAIL PROTECTED] writes:
Uwe See ?formula and its See Also Section on how to do formula
Uwe manipulation. There's also an example on how to construct a
Uwe formula.
Russell In order to use the 'as.formula(paste(response, ~
I got errors from Prof. Lumley's code, but the following
modification produced for me something that seemed to fit his description:
data(airquality)
formula- log(Ozone)~factor(Month)
m-lm(formula,data=airquality)
a-anova(m)
mf-model.frame(m)
pairwise.t.test(mf[,1], mf[,2])
hope this
I am writing a little abstraction for a series of tests. For example,
I am running an anova and kruskal.test on a one-factor model. That
isn't a particular problem, I have an interface like:
my.function - function(model,data) {
print(deparse(substitute(data)))
a -
On 2003.06.13 02:11, g wrote:
Hi,
Can someone set me straight as to how to write formulas in R to
indicate:
complete independence [A][B][C]
Freq ~ A + B + C
joint independence [AB][C]
Freq ~ A * B + C
conditional independence [AC][BC]
Freq ~ A * C + B * C
nway interaction
Hi,
Can someone set me straight as to how to write formulas in R to indicate:
complete independence [A][B][C]
joint independence [AB][C]
conditional independence [AC][BC]
nway interaction [AB][AC][BC]
?
For example, if I have 4 factors:
hair colour, eye colour,
:12 AM
To: [EMAIL PROTECTED]
Subject: [R] formula (joint, conditional independence, etc.) -
mosaicplots
Hi,
Can someone set me straight as to how to write formulas in R
to indicate:
complete independence [A][B][C]
joint independence [AB][C]
conditional independence
On 15 Mar 2003 at 6:22, Peng wrote:
I don't know of a way to do this with formulas.
But what you want to do is simply multiply each row
of a numeric matrix (doesn't matter that the matrix was formed by
a call to model.matrix) with a number, which for row i
can be taken as element i of a vector.
Hi, R or S+ users,
I want to make a simple transformation for the model,
but for the whole design matrix.
The model is distance ~ age * Sex, where Sex is a
factor. So the design matrix may look like the
following:
(Intercept) age SexFemale age:SexFemale
1 1 8 0
45 matches
Mail list logo