Hello, I want to arrange data from a table to perform a simple regression. All the examples I saw deal with paired data, e.g. 'x' and 'y' have the same dimensions (e.g. 5 values for x and 5 for y). But I have more than one 'y' for each 'x' value, e.g. the data file has a x = 0, 30, 60, and 120 columns. And for each of them I have several replicate responses (e.g. individuals), not allways the same number. After I read the data with read.table(), ending with 4 columns, what is next? how can I regress this against c(0, 30, 60, 120)? 0 --> n1 y values 30 --> n2 y values 60 --> n3 y values 120 --> n4 y values Thanks, Tomas
Hi not sure what do you want to do but what about y<-colMeans(your.data) x<-c(0,30,60,120) fit<-lm(y~x) Is this what you want? Better to use advice suggested in posting guide and to show some reproducible example. HTH Petr On 24 Apr 2006 at 5:15, Tom?s Revilla wrote: Date sent: Mon, 24 Apr 2006 05:15:58 -0400 From: "Tom?s Revilla" <tomlists at gmail.com> To: r-help at stat.math.ethz.ch Subject: [R] arrange data for simple regression analysis> Hello, I want to arrange data from a table to perform a simple > regression. All the examples I saw deal with paired data, e.g. 'x' and > 'y' have the same dimensions (e.g. 5 values for x and 5 for y). > > But I have more than one 'y' for each 'x' value, e.g. the data file > has a x = 0, 30, 60, and 120 columns. And for each of them I have > several replicate responses (e.g. individuals), not allways the same > number. After I read the data with read.table(), ending with 4 > columns, what is next? how can I regress this against c(0, 30, 60, > 120)? > > 0 --> n1 y values > 30 --> n2 y values > 60 --> n3 y values > 120 --> n4 y values > > Thanks, > > Tomas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
Here are a couple of possibilities using the builtin iris data set. Note that although the coefficients come out the same, the degrees of freedom, etc., would differ:> n <- rep(1:3, 50) > lm(Petal.Length ~ Petal.Width, iris, weight = n)Call: lm(formula = Petal.Length ~ Petal.Width, data = iris, weights = n) Coefficients: (Intercept) Petal.Width 1.057 2.262> lm(Petal.Length ~ Petal.Width, iris[rep(1:nrow(iris), n),])Call: lm(formula = Petal.Length ~ Petal.Width, data = iris[rep(1:nrow(iris), n), ]) Coefficients: (Intercept) Petal.Width 1.057 2.262 On 4/24/06, Tom?s Revilla <tomlists at gmail.com> wrote:> Hello, I want to arrange data from a table to perform a simple > regression. All the examples I saw deal with paired data, e.g. 'x' and > 'y' have the same dimensions (e.g. 5 values for x and 5 for y). > > But I have more than one 'y' for each 'x' value, e.g. the data file > has a x = 0, 30, 60, and 120 columns. And for each of them I have > several replicate responses (e.g. individuals), not allways the same > number. After I read the data with read.table(), ending with 4 > columns, what is next? how can I regress this against c(0, 30, 60, > 120)? > > 0 --> n1 y values > 30 --> n2 y values > 60 --> n3 y values > 120 --> n4 y values > > Thanks, > > Tomas > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >