Re: [R] Linear model and approx function

2023-12-09 Thread Bert Gunter
1. You should regress Elevation on Volume, no? 2. You are calling lm incorrectly for prediction. Please read ?lm and related links carefully and/or consult a tutorial. R-Help is really not the first place you should look for this sort of detailed info. 3. I think this is what you want: lm1 <- lm

Re: [R] linear model contrast in R

2019-05-13 Thread Richard M. Heiberger
I think you might be looking for ?contrasts to form the contrast matrix. Rich On Mon, May 13, 2019 at 7:31 AM Witold E Wolski wrote: > > I am looking for a function to compute contrasts with a interface > similar to that of > > lmerTest::contest > multcomp::glht > > i.e. taking the model and a c

Re: [R] Linear model vs Mixed model

2016-07-13 Thread Utkarsh Singhal
Thanks Brian for all your kind help. "didn't mean to imply that the different parameterization of the contrasts would make the lm estimates agree more with the lmer estimates, only that it might be easier to compare the regression summary output to see how similar/dissimilar they were ". Got it no

Re: [R] Linear model vs Mixed model

2016-07-13 Thread Cade, Brian
Utkarsh: I think the differences between the lm and lmer estimates of the intercept are consistent with the regularization effect expected with mixed-effects models where the estimates shrink towards the mean slightly. I don't think there is any reason to expect exact agreement between the lm and

Re: [R] Linear model vs Mixed model

2016-07-13 Thread Utkarsh Singhal
Hi Brian, This makes some sense to me theoretically, but doesn't pan out with my experiment. The contrasts default was the following as you said: > options("contrasts") $contrasts unordered ordered "contr.treatment" "contr.poly" I changed it as follows: > options(contracts

Re: [R] Linear model vs Mixed model

2016-07-12 Thread Cade, Brian
Your lm() estimates are using the default contrasts of contr.treatment, providing an intercept corresponding to your subject 308 and the other subject* estimates are differences from subject 308 intercept. You could have specified this with contrasts as contr.sum and the estimates would be more ea

Re: [R] Linear model vs Mixed model

2016-07-12 Thread Utkarsh Singhal
Hello Thierry, Thank you for your quick response. Sorry, but I am not sure if I follow what you said. I get the following outputs from the two models: > coef(lmer(Reaction ~ Days + (1| Subject), sleepstudy)) Subject(Intercept) Days 308292.1888 10.46729 309173.5556 10.46729 3101

Re: [R] Linear model vs Mixed model

2016-07-12 Thread Thierry Onkelinx
The parametrisation is different. The intercept in model 1 is the effect of the "average" subject at days == 0. The intercept in model 2 is the effect of the first subject at days == 0. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Bio

Re: [R] Linear Model and Missing Data in Predictors

2016-03-15 Thread William Dunlap via R-help
One technique for dealing with this is called 'multiple imputation'. Google for 'multiple imputation in R' to find R packages that implement it (e.g., the 'mi' package). Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Mar 15, 2016 at 8:14 AM, Lorenzo Isella wrote: > Dear All, > A situation

Re: [R] Linear Model and Missing Data in Predictors

2016-03-15 Thread Jeff Newmiller
IMHO this is not a question about R... it is a question about statistics whether R is involved or not. As such, a forum like stats.stackexchange.com would be better suited to address this. FWIW I happen to think that expecting R to solve this for you is unreasonable. -- Sent from my phone. Ple

Re: [R] linear model solving

2015-11-16 Thread Rolf Turner
On 16/11/15 20:49, Ragia Ibrahim wrote: Dear group IF I had an objective function and some constrains formed in linear model form. is there a way,..library in R that helps me to solve such amodel and find the unknown variable in it? This is a very ill-posed question and is unlikely to provoke

Re: [R] Linear Model with Discrete Data

2013-06-13 Thread David Winsemius
On Jun 13, 2013, at 2:21 PM, Bert Gunter wrote: > Lorenzo: > > 1. This is a statistics question, not an R question. > > 2. Your statistical background appears inadequate -- it looks like > Poisson regression, which would fall under "generalized linear > models". But it depends on how "discrete

Re: [R] Linear Model with Discrete Data

2013-06-13 Thread Bert Gunter
Lorenzo: 1. This is a statistics question, not an R question. 2. Your statistical background appears inadequate -- it looks like Poisson regression, which would fall under "generalized linear models". But it depends on how "discrete" discrete is (on some level, all measurements are discrete, dis

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-04 Thread Cecilia Carmo
Carmo Cc: r-help@r-project.org; Adams, Jean Assunto: Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data On 2013-04-04 02:11, Cecilia Carmo wrote: > Thank you all. I'm very happy with this solution. Just two questions: > I use mutate() with package

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-04 Thread Peter Ehlers
ter Ehlers De: Peter Ehlers [ehl...@ucalgary.ca] Enviado: quarta-feira, 3 de Abril de 2013 19:01 Para: Adams, Jean Cc: Cecilia Carmo; r-help@r-project.org Assunto: Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data A

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-04 Thread Cecilia Carmo
Carmo De: Peter Ehlers [ehl...@ucalgary.ca] Enviado: quarta-feira, 3 de Abril de 2013 19:01 Para: Adams, Jean Cc: Cecilia Carmo; r-help@r-project.org Assunto: Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data A few minor improvements to Jean's post

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-03 Thread Rolf Turner
On 04/04/2013 07:54 AM, Adams, Jean wrote: Peter. For suggestion 1, what advantages are there to using coef() rather than $coef? Just thought I'd chip in: It is considered, uh, politically correct to use extractor functions rather than digging out components of objects in a "direct" manner.

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-03 Thread Adams, Jean
Peter. For suggestion 1, what advantages are there to using coef() rather than $coef? For suggestion 2, thanks! I'm new to the plyr package and wasn't aware of the mutate() function. Jean On Wed, Apr 3, 2013 at 1:01 PM, Peter Ehlers wrote: > A few minor improvements to Jean's post suggested

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-03 Thread Peter Ehlers
A few minor improvements to Jean's post suggested inline below. On 2013-04-03 05:41, Adams, Jean wrote: Cecilia, Thanks for providing a reproducible example. Excellent. You could use the ddply() function in the plyr package to fit the model for each industry and year, keep the coefficients, a

Re: [R] linear model coefficients by year and industry, fitted values, residuals, panel data

2013-04-03 Thread Adams, Jean
Cecilia, Thanks for providing a reproducible example. Excellent. You could use the ddply() function in the plyr package to fit the model for each industry and year, keep the coefficients, and then estimate the fitted and residual values. Jean library(plyr) coef <- ddply(final3, .(industry, yea

Re: [R] Linear Model Prediction

2012-07-24 Thread arun
Hello, The example below gives you some information about using predict().   This was originally used to predict NAs. dat1<-data.frame(Year=1962:1986,Discharge=c(rnorm(15,25),rep(NA,5),1:5)) lm1<-lm(Discharge~Year,dat1) dat2<-data.frame(Year=dat1[,1]) dat1$fit<-predict(lm1,newdata=dat2) #The c

Re: [R] Linear Model Prediction

2012-07-24 Thread R. Michael Weylandt
On Tue, Jul 24, 2012 at 2:06 PM, wrote: > Yes, why wouldn't I? It's a linear model between two sets of data: x and y. Conventionally, one predicts y based on x -- which is specified y ~ x, not x ~ y. (Predictors on the RHS, predicted on the LHS) > > Also, what would the new data be if i want to

Re: [R] Linear Model Prediction

2012-07-24 Thread cm
Yes, why wouldn't I? It's a linear model between two sets of data: x and y. Also, what would the new data be if i want to predict into the future? So, for example, the data goes from a month ago to today. I want to predict what tomorrow's data would be. So what is "newdata"? -- View this mes

Re: [R] Linear Model Prediction

2012-07-24 Thread R. Michael Weylandt
On Jul 24, 2012, at 1:38 PM, cm wrote: > How do I set it up? Because when I do predict(model) I get a ton of points, > not just one. You need to supply newdata= . predict() without new data gives predicted values for the predictors you for the model to. Incidentally, repeating Uwe -- are

Re: [R] Linear Model Prediction

2012-07-24 Thread cm
How do I set it up? Because when I do predict(model) I get a ton of points, not just one. - Original Message - From: "Uwe Ligges-3 [via R]" Date: Tuesday, July 24, 2012 2:28 pm Subject: Re: Linear Model Prediction To: cm > > > > > On 24.07.2012 20:20, cm wrote: > > I have data X a

Re: [R] Linear Model Prediction

2012-07-24 Thread Uwe Ligges
On 24.07.2012 20:20, cm wrote: I have data X and Y, and I want to predict what the very next point would be based off the model. This is what I have: model=lm(x~y) Hmmm, are you sure about the above code? I think I want to use the predict function, but I'm not exactly sure what to do. Y

Re: [R] Linear model - coefficients

2011-06-12 Thread Robert Ruser
Hi Weidong, thank you very much. It really works fine. Robert 2011/6/12 Weidong Gu : > this may work. > X<-data.frame(sapply(X,function(x) as.factor(x))) > reg3=lm(Y~.,data=X) > dummy.coef(reg3) > > Weidong Gu > > On Sun, Jun 12, 2011 at 4:55 PM, Robert Ruser wrote: >> Hi, >> but I want to get t

Re: [R] Linear model - coefficients

2011-06-12 Thread Weidong Gu
this may work. X<-data.frame(sapply(X,function(x) as.factor(x))) reg3=lm(Y~.,data=X) dummy.coef(reg3) Weidong Gu On Sun, Jun 12, 2011 at 4:55 PM, Robert Ruser wrote: > Hi, > but I want to get the coefficients for every variables from x1 to x5. > (x1 was an example) > > Robert > > 2011/6/12 Jorge

Re: [R] Linear model - coefficients

2011-06-12 Thread Robert Ruser
Hi, but I want to get the coefficients for every variables from x1 to x5. (x1 was an example) Robert 2011/6/12 Jorge Ivan Velez : > Hi Robert, > > Try this: > reg2 <- lm( Y ~ factor(x1) + factor(x2) + factor(x3) + factor(x4) + > factor(x5) - 1, data = X  ) > cof(ref2) > HTH, > Jorge > > On Sun, J

Re: [R] Linear model - coefficients

2011-06-12 Thread Jorge Ivan Velez
Hi Robert, Try this: reg2 <- lm( Y ~ factor(x1) + factor(x2) + factor(x3) + factor(x4) + factor(x5) - 1, data = X ) cof(ref2) HTH, Jorge On Sun, Jun 12, 2011 at 4:40 PM, Robert Ruser <> wrote: > Prof. Ripley, thank you very much for the answer but wanted to get > something else. There is an

Re: [R] Linear model - coefficients

2011-06-12 Thread Robert Ruser
Prof. Ripley, thank you very much for the answer but wanted to get something else. There is an example and an explanation: options(contrasts=c("contr.sum","contr.poly")) # contr.sum uses ‘sum to zero contrasts’ Y <- c(6,3,5,2,3,1,1,6,6,6,7,4,1,6,6,6,6,1) X <- structure(list(x1 = c(2L, 3L, 1L, 3L,

Re: [R] Linear model - coefficients

2011-06-12 Thread Prof Brian Ripley
?dummy.coef (NB: 'R' does as you tell it, and if you ask for the default contrasts you get coefficients a2 and a3, not a1 and a2. So perhaps you did something else and failed to tell us? And see the comment in ?dummy.coef about treatment contrasts.) On Sun, 12 Jun 2011, Robert Ruser wrote

Re: [R] Linear Model with curve fitting parameter?

2011-04-04 Thread stephen sefick
Thank you very much for all of your help. On Mon, Apr 4, 2011 at 6:10 PM, Steven McKinney wrote: > > >> -Original Message- >> From: stephen sefick [mailto:ssef...@gmail.com] >> Sent: April-04-11 2:49 PM >> To: Steven McKinney >> Subject: Re: [R] Linea

Re: [R] Linear Model with curve fitting parameter?

2011-04-04 Thread Steven McKinney
> -Original Message- > From: stephen sefick [mailto:ssef...@gmail.com] > Sent: April-04-11 2:49 PM > To: Steven McKinney > Subject: Re: [R] Linear Model with curve fitting parameter? > > Steven: > > I am really sorry for my confusion. I hope this now makes s

Re: [R] Linear Model with curve fitting parameter?

2011-04-04 Thread Steven McKinney
> -Original Message- > From: stephen sefick [mailto:ssef...@gmail.com] > Sent: April-03-11 5:35 PM > To: Steven McKinney > Cc: R help > Subject: Re: [R] Linear Model with curve fitting parameter? > > Steven: > > You are exac

Re: [R] Linear Model with curve fitting parameter?

2011-04-03 Thread stephen sefick
McKinney wrote: > >> -Original Message- >> From: stephen sefick [mailto:ssef...@gmail.com] >> Sent: April-01-11 5:44 AM >> To: Steven McKinney >> Cc: R help >> Subject: Re: [R] Linear Model with curve fitting parameter? >> >> Setting Z=Q-A would

Re: [R] Linear Model with curve fitting parameter?

2011-04-01 Thread Steven McKinney
> -Original Message- > From: stephen sefick [mailto:ssef...@gmail.com] > Sent: April-01-11 5:44 AM > To: Steven McKinney > Cc: R help > Subject: Re: [R] Linear Model with curve fitting parameter? > > Setting Z=Q-A would be the incorrect dimensions. I could Z=Q

Re: [R] Linear Model with curve fitting parameter?

2011-04-01 Thread Peter Ehlers
On 2011-04-01 05:44, stephen sefick wrote: Setting Z=Q-A would be the incorrect dimensions. I could Z=Q/A. Is fitting a nls model the same as fitting an ols? These data are hydraulic data from ~47 sites. To access predictive ability I am removing one site fitting a new model and then accessin

Re: [R] Linear Model with curve fitting parameter?

2011-04-01 Thread stephen sefick
Setting Z=Q-A would be the incorrect dimensions. I could Z=Q/A. Is fitting a nls model the same as fitting an ols? These data are hydraulic data from ~47 sites. To access predictive ability I am removing one site fitting a new model and then accessing the fit with a myriad of model assessment c

Re: [R] Linear Model with curve fitting parameter?

2011-03-31 Thread Steven McKinney
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of stephen sefick > Sent: March-31-11 3:38 PM > To: R help > Subject: [R] Linear Model with curve fitting parameter? > > I have a model Q=K*A*(R^r)*(S^s) > > A, R, and S are data

Re: [R] linear model - lm (Adjusted R-squared)?

2011-03-04 Thread Erik Iverson
See: http://en.wikipedia.org/wiki/Coefficient_of_determination#Adjusted_R2 and the implementation in summary.lm : ans$adj.r.squared <- 1 - (1 - ans$r.squared) * ((n - df.int)/rdf) Brian Smith wrote: Hi, Sorry for the naive question, but what exactly does the 'Adjusted R

Re: [R] linear model lme4

2011-02-25 Thread Doran, Harold
No, as the error states, you need random effects in lmer. But, you don't for lm() and that is what you're running with no random effects. However, some caution is warranted on the comparison. > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]

Re: [R] linear model with similar response predictor

2010-08-05 Thread David Winsemius
On Aug 5, 2010, at 6:50 AM, Giuseppe Amatulli wrote: Hi, can somebody tell me why R is not able to calculate a linear model written in this way? lm (seq(1:100)~seq(1:100)) Call: lm(formula = seq(1:100) ~ seq(1:100)) Coefficients: (Intercept) 50.5 Warning messages: 1: In model.matrix

Re: [R] linear model with similar response predictor

2010-08-05 Thread Erik Iverson
On 08/05/2010 05:50 AM, Giuseppe Amatulli wrote: Hi, can somebody tell me why R is not able to calculate a linear model written in this way? lm (seq(1:100)~seq(1:100)) Call: lm(formula = seq(1:100) ~ seq(1:100)) Coefficients: (Intercept) 50.5 Warning messages: 1: In model.matrix.def

Re: [R] linear model and by()

2009-11-14 Thread David Winsemius
On Nov 13, 2009, at 11:49 AM, Sam Albers wrote: Hello R list, snipped answered question Sorry to not use your data but it's not in a form that lends itself very well to quick testing. If you had included the input commands I might have tried it. No problem not use my data. For futur

Re: [R] linear model and by()

2009-11-13 Thread Ista Zahn
On Fri, Nov 13, 2009 at 11:49 AM, Sam Albers wrote: > No problem not use my data. For future reference, would it have been easier > to attach a .csv file and then include the appropriate read.csv command? I > realized that the easier one makes it to help, the easier it is to get a > response. > >

Re: [R] linear model and by()

2009-11-13 Thread Sam Albers
> Hello R list, >> >> This is a question for anyone who has used the by() command. I would like >> to >> perform a regression on a data frame by several factors. Using by() I >> think >> that I have able to perform this using the following: >> >> lm.r <- by(master, list(Sectionf=Sectionf, startd=s

Re: [R] linear model and by()

2009-11-12 Thread David Winsemius
On Nov 12, 2009, at 8:26 PM, Sam Albers wrote: Hello R list, This is a question for anyone who has used the by() command. I would like to perform a regression on a data frame by several factors. Using by() I think that I have able to perform this using the following: lm.r <- by(master, l

Re: [R] linear model and by()

2009-11-12 Thread Ista Zahn
Hi, You have not given us all the data needed to reproduce your analysis (what is SectionF?), but the issue is probably that lm.r is a list and you're not treating it that way. Try srt(lm.r) and summary(lm.r[[1]]) You may also want to look at the the lmList() function in the lme4 package. -Ist

Re: [R] linear model with coefficient constraints

2009-10-06 Thread Dieter Menne
Rnewb wrote: > > I would like to perform a regression like the one below: > > lm(x ~ 0 + a1 + a2 + a3 + b1 + b2 + b3 + c1 + c2 + c3, data=data) > > However, the data has the property that a1+a2+a3 = A, b1+b2+b3 = B, and > c1+c2+c3 = C, where A, B, > Ravi Varadhan has an example how this co

Re: [R] Linear Model "NA" Value Test

2009-09-21 Thread Ted Harding
On 21-Sep-09 20:38:25, Douglas M. Hultstrand wrote: > Hello, > > I am deriving near real-time liner relationships based on 5-min > precipitation data, sometimes the non-qced data result in a > slope of NA. I am trying to read the coefficient (in this example x) > to see if it is equal to NA, if it

Re: [R] Linear Model "NA" Value Test

2009-09-21 Thread David Winsemius
On Sep 21, 2009, at 4:50 PM, David Winsemius wrote: On Sep 21, 2009, at 4:38 PM, Douglas M. Hultstrand wrote: Hello, I am deriving near real-time liner relationships based on 5-min precipitation data, sometimes the non-qced data result in a slope of NA. I am trying to read the coefficien

Re: [R] Linear Model "NA" Value Test

2009-09-21 Thread David Winsemius
On Sep 21, 2009, at 4:38 PM, Douglas M. Hultstrand wrote: Hello, I am deriving near real-time liner relationships based on 5-min precipitation data, sometimes the non-qced data result in a slope of NA. I am trying to read the coefficient (in this example x) to see if it is equal to NA, if

Re: [R] Linear Model "NA" Value Test

2009-09-21 Thread Erik Iverson
> if("fit$coef[[2]]" == "NA") {.cw = 1} See ?is.na __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-conta

Re: [R] linear model with interaction / segments

2009-08-29 Thread Gavin Simpson
On Sat, 2009-08-29 at 12:56 +0100, Markus Gesmann wrote: > Dear R-help, > > Suppose I have the following data: > > df=data.frame(x=1:10, y=c(1,2,3,4,5,12,14,16,18,20)) > plot(y~x, df, t="b") > > How can I fit a model which estimates the slopes between x = 1-5, 5-6, > and 6-10? Does the segmen

Re: [R] linear model with interaction / segments

2009-08-29 Thread David Winsemius
On Aug 29, 2009, at 7:56 AM, Markus Gesmann wrote: Dear R-help, Suppose I have the following data: df=data.frame(x=1:10, y=c(1,2,3,4,5,12,14,16,18,20)) plot(y~x, df, t="b") How can I fit a model which estimates the slopes between x = 1-5, 5-6, and 6-10? Adding the factor f: df$f <- gl(

Re: [R] linear model: Test difference between coefficients and given values (t.test?)

2009-08-09 Thread Achim Zeileis
On Sat, 8 Aug 2009, Katharina May wrote: Thanks to somebody I got the hint to use offset for the purpose of validating if there's a difference between the intercept and slope of a model and some provided values for the coefficients intercept and slope. You could also use a Wald test for a line

Re: [R] linear model: Test difference between coefficients and given values (t.test?)

2009-08-08 Thread Katharina May
Thanks to somebody I got the hint to use offset for the purpose of validating if there's a difference between the intercept and slope of a model and some provided values for the coefficients intercept and slope. I read ?model.offset and I'm still struggling to use it for my purpose. If I understoo

Re: [R] Linear model with coefficient restriction

2009-06-05 Thread David Winsemius
On Jun 5, 2009, at 11:10 AM, Axel Leroix wrote: Hi every one I perform a simple linear regression lm(a b + c + d , data = data1) How to say to R to perform and print the regression with restricting the coefficient of the variable c to be equal to 0.1. ?lm Examine material on specifyin

Re: [R] Linear model, finding the slope

2009-04-03 Thread Charles Annis, P.E.
I'm not sure what you are doing when you "Normalize." Would you explain? To see if the slope is significant, look at the model summary, in your example: summary(model) Charles Annis, P.E. charles.an...@statisticalengineering.com phone: 561-352-9699 eFax: 614-455-3265 http://www.Statistical

Re: [R] Linear model, finding the slope

2009-04-03 Thread Uwe Ligges
Melissa2k9 wrote: Hi for some data I working on I am merely plotting time against temperature for a variable named filmclip. So for example, I have volunteers who watched various film clips and have used infared camera to monitor the temperature on their face at every second of the clip. Th

Re: [R] Linear model

2009-02-11 Thread Kingsford Jones
On Wed, Feb 11, 2009 at 1:36 PM, kayj wrote: > > I want to know how accurate are the p-values when you do linear regression in > R? > > I was looking at the variable x3 and the t=10.843 and the corresponding > p-value=2e-16 which is the same p-value for the intercept where the t-value > for the in

Re: [R] Linear model

2009-02-11 Thread Bill.Venables
If you look carefully you will see that the p-value is actually < 2e-16 where the "<" sign is telling you this is an upper limit. For many machines this is the double precision epsilon value: > .Machine$double.eps [1] 2.220446e-16 So there is no pretence to accuracy, other than "the value is

Re: [R] Linear model: contrasts

2009-02-06 Thread Ian Fiske
The problem comes from mixing up general linear model (LM) theory to compute B with the classical anova estimators. The two methods use different approaches to solving the normal equations. LM theory uses any generalized inverse of X'X to solve the normal equations. Yours comes from ginv() whic

Re: [R] Linear model with one known coordinate

2008-08-28 Thread Philipp Pagel
> I have a set of points (measurements) and I used lm() to obtain their linear > regression model. From the biological background this line must pass through > a point (100,0). Our dataset is not optimal and it shows a slight deviation > from that coordinate. How can I add the restraint to the mode

Re: [R] linear model in the repeated data type~

2008-06-05 Thread Austin, Matt
hursday, June 05, 2008 3:03 PM To: Manli Yan Cc: r-help@r-project.org Subject: Re: [R] linear model in the repeated data type~ allFits <- lmList(y ~ t|id, data=table1, pool=FALSE) allCoefs <- sapply(allFits, coef) ## preferred by me or allCoefs <- list(length(allFits)) for(i in 1:le

Re: [R] linear model in the repeated data type~

2008-06-05 Thread Austin, Matt
IL PROTECTED] Sent: Wednesday, June 04, 2008 9:12 PM To: Austin, Matt Cc: r-help@r-project.org Subject: Re: [R] linear model in the repeated data type~ hi:lot thanks,how to use list to extract,I type allFit$coefficents,it came to nothing, such as I need to extract the estimates,how to do it by using

Re: [R] linear model in the repeated data type~

2008-06-04 Thread Manli Yan
hi:lot thanks,how to use list to extract,I type allFit$coefficents,it came to nothing, such as I need to extract the estimates,how to do it by using list 2008/6/3 Austin, Matt <[EMAIL PROTECTED]>: > How about > > > library(nlme) > allFits <- lmList(y ~ t|id, data=table1, pool=FALSE) > > or > > a

Re: [R] linear model with the repeated data type~

2008-06-04 Thread Henrique Dallazuanna
Try this: f <- function(x)any(is.na(coefficients(x))) models <- by(table1[c("y", "t")], table1$id, FUN=lm) models[!unlist(lapply(models, f))] On Wed, Jun 4, 2008 at 6:20 PM, Manli Yan <[EMAIL PROTECTED]> wrote: > here is the data: > y<-c(5,2,3,7,9,0,1,4,5) > id<-c(1,1,6,6,7,8,15,15,19) > t<-c

Re: [R] linear model in the repeated data type~

2008-06-03 Thread Moshe Olshansky
Try something like this: fits <- list(500) for (i in 1:500) { if (sum(table1$id == i) == 0) fits[[i]] <- NA else fits[[i]] <- lm(y~t,data=table1,subset=(id==i)) } --- On Wed, 4/6/08, Manli Yan <[EMAIL PROTECTED]> wrote: > From: Manli Yan <[EMAIL PROTECTED]> > Subject: [R] linear model in the re

Re: [R] linear model in the repeated data type~

2008-06-03 Thread Austin, Matt
How about library(nlme) allFits <- lmList(y ~ t|id, data=table1, pool=FALSE) or allFits <- by(table1, table1$id, function(x) lm(y ~ t, data=x)) Both ways store the results as a list, so you can access individual results using list extraction. --Matt -Original Message- From: [EMAIL