leo_aries
2008-Jan-28 16:16 UTC
[R] How to get out the t-test value matrix for a linear regression ?
Hi, all I've written some R script to calculate the linear regression of a matrix. Here below is my script:>x<-matrix(scan("h:/data/xxx.dat",0),nrow=46,ncol=561,byrow=TRUE)>year <- NULL >year <- cbind(year,as.matrix(x[,1]))>lm.sol<-lm(x~year) >xtrend<-coef(lm.sol)[2,] # get the matrix of regression coefficient>t.test<- ? # also want to get a similar matrix of t-test value for the regression coefficient>class(summary(lm.sol)) > "listof" >class(summary(lm.sol)) >"listof" # the t-test values are in the obj "summary(lm.sol)", but how to get them outas a matrix similar as the above"xtrend"? Anyone can help me? Thanks ! Regards Leo 2008-01-28 leo_aries [[alternative HTML version deleted]]
Peter Dalgaard
2008-Jan-28 16:43 UTC
[R] How to get out the t-test value matrix for a linear regression ?
leo_aries wrote:> Hi, all > > I've written some R script to calculate the linear regression of a matrix. > Here below is my script: > > >> x<-matrix(scan("h:/data/xxx.dat",0),nrow=46,ncol=561,byrow=TRUE) >> > > >> year <- NULL >> year <- cbind(year,as.matrix(x[,1])) >> > > >> lm.sol<-lm(x~year) >> xtrend<-coef(lm.sol)[2,] # get the matrix of regression coefficient >> > > >> t.test<- ? # also want to get a similar matrix of t-test value for the regression coefficient >> > > >> class(summary(lm.sol)) >> "listof" >> class(summary(lm.sol)) >> "listof" # the t-test values are in the obj "summary(lm.sol)", but how to get them out >> > as a matrix similar as the above"xtrend"? > > Anyone can help me? Thanks ! >This seems to do it:> Y <- matrix(rnorm(10),5) > x <- rnorm(5) > sapply(coef(summary(lm(Y~x))),"[", TRUE, "t value")Response Y1 Response Y2 (Intercept) 0.5485488 2.021065 x -0.5175011 -2.225623 Or, a bit less sneaky> sapply(coef(summary(lm(Y~x))), function(X) X[,"t value"])Response Y1 Response Y2 (Intercept) 0.5485488 2.021065 x -0.5175011 -2.225623 -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Petr PIKAL
2008-Jan-28 16:46 UTC
[R] Odp: How to get out the t-test value matrix for a linear regression ?
Hi r-help-bounces at r-project.org napsal dne 28.01.2008 17:16:37:> Hi, all > > I've written some R script to calculate the linear regression of amatrix.> Here below is my script: > > >x<-matrix(scan("h:/data/xxx.dat",0),nrow=46,ncol=561,byrow=TRUE) > > >year <- NULL > >year <- cbind(year,as.matrix(x[,1])) > > >lm.sol<-lm(x~year) > >xtrend<-coef(lm.sol)[2,] # get the matrix of regression coefficient > > >t.test<- ? # also want to get a similar matrix oft-> test value for the regression coefficient > > >class(summary(lm.sol)) > > "listof" > >class(summary(lm.sol)) > >"listof" # the t-test values are in the obj > "summary(lm.sol)", but how to get them out > as a matrix similar as theabove"xtrend"?>str is your friend. Try, str(summary(lm.sol)) and you will find a structure of summary object.>From it it is quite easy to find thatsummary(lm.sol)$coef gives you a table with t.test values. Regards Petr> Anyone can help me? Thanks ! > > > > > > Regards > > > Leo > > > 2008-01-28 > > > > leo_aries > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.