[R] Formula in lm inside lapply

2007-08-15 Thread Li, Yan \(IED\)
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

Re: [R] Formula in lm inside lapply

2007-08-15 Thread Henrique Dallazuanna
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

Re: [R] Formula in lm inside lapply

2007-08-15 Thread Gabor Grothendieck
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)))

Re: [R] Formula in lm inside lapply

2007-08-15 Thread Weiwei Shi
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)})

Re: [R] Formula in lm inside lapply

2007-08-15 Thread Gabor Grothendieck
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:

Re: [R] Formula syntax question

2007-07-03 Thread Frank E Harrell Jr
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 -

[R] Formula syntax question

2007-07-03 Thread Isaac Kohane
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 ~

[R] formula for test statistics of arima coefficients

2007-02-06 Thread Leeds, Mark \(IED\)
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

[R] formula format for parameter estimation

2006-12-07 Thread Wayne Delport
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

Re: [R] Formula aruguments with NLS and model.frame()

2006-09-29 Thread Spencer Graves
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

Re: [R] Formula aruguments with NLS and model.frame()

2006-09-29 Thread Joe Byers
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

[R] Formula aruguments with NLS and model.frame()

2006-09-15 Thread Joe W. Byers
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

[R] formula restriction in multinom?

2005-05-09 Thread Berry, Mark R
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

RE: [R] formula restriction in multinom?

2005-05-09 Thread Berton Gunter
: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

Re: [R] formula in fixed-effects part of GLMM

2005-05-02 Thread Douglas Bates
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 +

Re: [R] formula in fixed-effects part of GLMM

2005-05-02 Thread Henric Nilsson
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,

Re: [R] formula in fixed-effects part of GLMM

2005-05-02 Thread 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 = ~1)) #error bar - GLMM (foo$formula,

RE: [R] formula in fixed-effects part of GLMM

2005-05-02 Thread Liaw, Andy
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 =

[R] formula in fixed-effects part of GLMM

2005-04-30 Thread weihong
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

[R] formula behaviour in model.matrix

2005-02-11 Thread Sundar Dorai-Raj
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:

Re: [R] formula behaviour in model.matrix

2005-02-11 Thread Prof Brian Ripley
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 -

Re: [R] formula and lm

2004-07-16 Thread Petr Pikal
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)

[R] formula

2004-07-15 Thread solares
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

[R] Formula

2004-07-15 Thread Vito Ricci
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)

Re: [R] formula

2004-07-15 Thread Luis Torgo
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

Re: [R] formula

2004-07-15 Thread Adaikalavan Ramasamy
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

Re: [R] formula

2004-07-15 Thread Adaikalavan Ramasamy
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

Re: [R] formula

2004-07-15 Thread Adaikalavan Ramasamy
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,

[R] formula and lm

2004-07-15 Thread solares
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

Re: [R] formula and lm

2004-07-15 Thread Spencer Graves
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

Re: [R] Formula of power.t.test

2004-05-13 Thread Uwe Ligges
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

[R] Formula of power.t.test

2004-05-12 Thread Xiaorong Chen
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

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Uwe Ligges
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 -

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Russell Senior
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 -

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Russell Senior
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 -

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Uwe Ligges
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:

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Russell Senior
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]

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Thomas Lumley
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, ~

Re: [R] formula parsing, using parts ...

2003-10-28 Thread Spencer Graves
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

[R] formula parsing, using parts ...

2003-10-27 Thread Russell Senior
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 -

Re: [R] formula (joint, conditional independence, etc.) - mosaicplots

2003-06-13 Thread David Meyer
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

[R] formula (joint, conditional independence, etc.) - mosaicplots

2003-06-12 Thread g
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,

RE: [R] formula (joint, conditional independence, etc.) - mosaicplots

2003-06-12 Thread Simon Blomberg
: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

Re: [R] formula, how to express for transforming the wholemodel.matrix, data=Orthodont

2003-03-16 Thread kjetil brinchmann halvorsen
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.

[R] formula, how to express for transforming the whole model.matrix,data=Orthodont

2003-03-15 Thread Peng
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