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

2008-06-05 Thread Austin, Matt
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:length(allFits)) allCoef[[i]] -  coef(allFits[[i]])

--Matt


From: Manli Yan [mailto:[EMAIL 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 list

2008/6/3 Austin, Matt [EMAIL PROTECTED]mailto:[EMAIL PROTECTED]:
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 PROTECTED]mailto:[EMAIL PROTECTED] [mailto:[EMAIL 
PROTECTED]mailto:[EMAIL PROTECTED]] On Behalf Of Manli Yan
Sent: Tuesday, June 03, 2008 9:07 PM
To: r-help@r-project.orgmailto:r-help@r-project.org
Subject: [R] linear model in the repeated data type~

 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(50,56,50,56,50,50,50,60,50)
table1-data.frame(y,id,t)//longitudinal data

what  I want to do is to use the linear model for each id ,then get the 
estimate value,like:

fit1-lm(y~t,data=table1,subset=(id==1))

but ,you can see the variable id is quite irregular,they are not arranaged in 
order and many number missing,if I write a loop by using for,it will give me 
a lot NA, and for sure ,I dont want to type id=## for about 500 times,any one 
know how to deal with it?

   [[alternative HTML version deleted]]

__
R-help@r-project.orgmailto: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.htmlhttp://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
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-contained, reproducible code.


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

2008-06-05 Thread Austin, Matt
Apologies, the second method should have been

allCoefs - vector(list, length(allFits))

for(i in 1:length(allFits)) allCoefs[[i]] -  coef(allFits[[i]])

--Matt


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Austin, Matt
Sent: Thursday, 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:length(allFits)) allCoef[[i]] -  coef(allFits[[i]])

--Matt


From: Manli Yan [mailto:[EMAIL 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 list

2008/6/3 Austin, Matt [EMAIL PROTECTED]mailto:[EMAIL PROTECTED]:
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 PROTECTED]mailto:[EMAIL PROTECTED] [mailto:[EMAIL 
PROTECTED]mailto:[EMAIL PROTECTED]] On Behalf Of Manli Yan
Sent: Tuesday, June 03, 2008 9:07 PM
To: r-help@r-project.orgmailto:r-help@r-project.org
Subject: [R] linear model in the repeated data type~

 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(50,56,50,56,50,50,50,60,50)
table1-data.frame(y,id,t)//longitudinal data

what  I want to do is to use the linear model for each id ,then get the 
estimate value,like:

fit1-lm(y~t,data=table1,subset=(id==1))

but ,you can see the variable id is quite irregular,they are not arranaged in 
order and many number missing,if I write a loop by using for,it will give me 
a lot NA, and for sure ,I dont want to type id=## for about 500 times,any one 
know how to deal with it?

   [[alternative HTML version deleted]]

__
R-help@r-project.orgmailto: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.htmlhttp://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
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-contained, reproducible code.

__
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-contained, reproducible code.


[R] linear model with the repeated data type~

2008-06-04 Thread Manli Yan
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(50,56,50,56,50,50,50,60,50)
table1-data.frame(y,id,t)//longitudinal data

the above is only part of data.
what  I want to do is to use the linear model for each id ,then get the
estimate value,like:

fit1-lm(y~t,data=table1,subset=(id==1))

but ,you can see the variable id is quite irregular,they are not arranaged
in order and many number missing,if I write a loop by using for,it will
give me a lot NA,
and for sure ,I dont want to type id=## for about 500 times
so,how to get all the esimates for each id,and exclude the NA,then record
those estimate in one table?

great thanks ~~

[[alternative HTML version deleted]]

__
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-contained, reproducible code.


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(50,56,50,56,50,50,50,60,50)
 table1-data.frame(y,id,t)//longitudinal data

 the above is only part of data.
 what  I want to do is to use the linear model for each id ,then get the
 estimate value,like:

 fit1-lm(y~t,data=table1,subset=(id==1))

 but ,you can see the variable id is quite irregular,they are not
 arranaged
 in order and many number missing,if I write a loop by using for,it will
 give me a lot NA,
 and for sure ,I dont want to type id=## for about 500 times
 so,how to get all the esimates for each id,and exclude the NA,then record
 those estimate in one table?

 great thanks ~~

[[alternative HTML version deleted]]

 __
 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-contained, reproducible code.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]

__
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-contained, reproducible code.


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

 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 PROTECTED] [mailto:[EMAIL PROTECTED]
 On Behalf Of Manli Yan
 Sent: Tuesday, June 03, 2008 9:07 PM
 To: r-help@r-project.org
 Subject: [R] linear model in the repeated data type~

  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(50,56,50,56,50,50,50,60,50)
 table1-data.frame(y,id,t)//longitudinal data

 what  I want to do is to use the linear model for each id ,then get the
 estimate value,like:

 fit1-lm(y~t,data=table1,subset=(id==1))

 but ,you can see the variable id is quite irregular,they are not
 arranaged in order and many number missing,if I write a loop by using
 for,it will give me a lot NA, and for sure ,I dont want to type id=##
 for about 500 times,any one know how to deal with it?

[[alternative HTML version deleted]]

 __
 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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
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-contained, reproducible code.


[R] linear model in the repeated data type~

2008-06-03 Thread Manli Yan
  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(50,56,50,56,50,50,50,60,50)
table1-data.frame(y,id,t)//longitudinal data

what  I want to do is to use the linear model for each id ,then get the
estimate value,like:

fit1-lm(y~t,data=table1,subset=(id==1))

but ,you can see the variable id is quite irregular,they are not arranaged
in order and many number missing,if I write a loop by using for,it will
give me a lot NA,
and for sure ,I dont want to type id=## for about 500 times,any one know how
to deal with it?

[[alternative HTML version deleted]]

__
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-contained, reproducible code.


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 PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Manli Yan
Sent: Tuesday, June 03, 2008 9:07 PM
To: r-help@r-project.org
Subject: [R] linear model in the repeated data type~

  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(50,56,50,56,50,50,50,60,50)
table1-data.frame(y,id,t)//longitudinal data

what  I want to do is to use the linear model for each id ,then get the 
estimate value,like:

fit1-lm(y~t,data=table1,subset=(id==1))

but ,you can see the variable id is quite irregular,they are not arranaged in 
order and many number missing,if I write a loop by using for,it will give me 
a lot NA, and for sure ,I dont want to type id=## for about 500 times,any one 
know how to deal with it?

[[alternative HTML version deleted]]

__
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-contained, reproducible code.

__
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-contained, reproducible code.


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 repeated data type~
 To: r-help@r-project.org
 Received: Wednesday, 4 June, 2008, 2:06 PM
 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(50,56,50,56,50,50,50,60,50)
 table1-data.frame(y,id,t)//longitudinal data
 
 what  I want to do is to use the linear model for each id
 ,then get the
 estimate value,like:
 
 fit1-lm(y~t,data=table1,subset=(id==1))
 
 but ,you can see the variable id is quite
 irregular,they are not arranaged
 in order and many number missing,if I write a loop by using
 for,it will
 give me a lot NA,
 and for sure ,I dont want to type id=## for about 500
 times,any one know how
 to deal with it?
 
   [[alternative HTML version deleted]]
 
 __
 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-contained,
 reproducible code.

__
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-contained, reproducible code.