[R] Covariance matrix in R with non-numeric variables
Dear R help forum members, I am modeling a gaussian distribution for a computational biology application and I am working in the statistical package R. In this regard, my problem is that I have to construct a covariance matrix with variables (non-numeric) and the covariance matrix is to be used in an maximizers of the likelihood function to predict the variables in the matrix. I am unable to do that because I do not have an idea of how to construct a covariance matrix with non-numeric variable in the matrix. Any help in this regard will be highly appreciated. Thanks in advance. Regards, B.Nataraj [[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] covariance matrix of model parameters
I am applying a hidden markov model on joint multivariate gaussian distribution for 2 vectors. I am using the depmixS4 package in R. Specifically, I am using the following code: mod-depmix(list(response = mom ~ mkt + p0 + p1, mkt~1), data = regvar, nstates = 2, family = list(gaussian(), gaussian()),instart = delta, trstart=Pi) It seems that depmixS4 doesnt output the covariance estimates of the parameters. What is the best package to obtain them? -- View this message in context: http://r.789695.n4.nabble.com/covariance-matrix-of-model-parameters-tp3928558p3928558.html Sent from the R help mailing list archive at Nabble.com. __ 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] covariance matrix TL-moments
The backage lmoments computes the L-moments covariances. does anyone know a backage to compute the TL-moments covariances thank -- Osama Abdelaziz Hussien Department of Statistics Faculty of Commerce Alexandria University Egypt __ 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] covariance matrix TL-moments
On 2011-07-03 04:48, osama hussien wrote: The backage lmoments computes the L-moments covariances. does anyone know a backage to compute the TL-moments covariances thank As far as I know the answer is no. But if you study the code of function varLmoments in package nsRFA and see how closely the computations correspond to the expression for the covariances of untrimmed L-moments that you get by setting s=0 and t=0 in Hosking (2007, last two displayed equations on p.3029), it should not be difficult to extend those computations to the trimmed case with s0 or t0. Reference: J.R.M. Hosking (2007). Some theory and practical uses of trimmed L-moments. Journal of Statistical Planning and Inference, 137, 3024-3039. J. R. M. Hosking __ 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] covariance matrix: a erro and simple mixed model question, but id not know answer sorry
Let me clarify the output I want to create: Source X1 (var) X2 (var) X1X2 (cov) gen var(X1) var(X2) cov(x1X2) block var(X1) var(X2) cov(x1x2) error/ res var(x1) var(x2) cov(x1x2) I need to do posterior analysis out of this table Thanks in advance Maya On Sun, Apr 17, 2011 at 9:59 PM, Maya Joshi maya.d.jo...@gmail.com wrote: Dear list I need your help: Execuse me for my limited R knowledge. #example data set set.seed (134) lm=c(1:4) block = c(rep(lm,6)) gen - c(rep(1, 4), rep(2, 4), rep(3, 4), rep(4, 4),rep(5, 4),rep(6, 4)) X1 = c( rnorm (4, 10, 4), rnorm (4, 12, 6), rnorm (4, 10, 7),rnorm (4, 5, 2), rnorm (4, 8, 4), rnorm (4,7, 2)) X2 = X1 + rnorm(length(X1), 0,3) yvar - c(X1, X2) X - c(rep( 1, length(X1)), rep( 2, length(X2))) # dummy x variable dataf - data.frame(as.factor(block), as.factor(gen), as.factor(X), yvar ) My objective to estimate variance-covariance between two variables X1 and X2. Means that I need to fit something like unstructure (UN) covariance structure. Question 1: I got the following error require(lme4); fm1Gen - lmer(yvar ~ X + gen +(1|block), data= dataf) # Question 1: should I consider X fixed or random Error in model.frame.default(data = dataf, formula = yvar ~ X + gen + : variable lengths differ (found for 'gen') A tried nlme too. require(nlme) fm2Gen - lme(yvar ~ X + gen, random= ~ 1|block, data= dataf) Error in model.frame.default(formula = ~yvar + X + gen + block, data = list( : variable lengths differ (found for 'gen') # similar error Question 2: How can get I covariance matrix between X1 and X2 either using lme4 or lmer. X1X2 X1 Var (X1) Cov(X1,X2) X2 Cov(X1, X2) Var(X2) Should I put gen in the model to do this? Should I specify something in * correlation* = Thank you for your time Maya [[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] covariance matrix: a erro and simple mixed model question, but id not know answer sorry
Dear list I need your help: Execuse me for my limited R knowledge. #example data set set.seed (134) lm=c(1:4) block = c(rep(lm,6)) gen - c(rep(1, 4), rep(2, 4), rep(3, 4), rep(4, 4),rep(5, 4),rep(6, 4)) X1 = c( rnorm (4, 10, 4), rnorm (4, 12, 6), rnorm (4, 10, 7),rnorm (4, 5, 2), rnorm (4, 8, 4), rnorm (4,7, 2)) X2 = X1 + rnorm(length(X1), 0,3) yvar - c(X1, X2) X - c(rep( 1, length(X1)), rep( 2, length(X2))) # dummy x variable dataf - data.frame(as.factor(block), as.factor(gen), as.factor(X), yvar ) My objective to estimate variance-covariance between two variables X1 and X2. Means that I need to fit something like unstructure (UN) covariance structure. Question 1: I got the following error require(lme4); fm1Gen - lmer(yvar ~ X + gen +(1|block), data= dataf) # Question 1: should I consider X fixed or random Error in model.frame.default(data = dataf, formula = yvar ~ X + gen + : variable lengths differ (found for 'gen') A tried nlme too. require(nlme) fm2Gen - lme(yvar ~ X + gen, random= ~ 1|block, data= dataf) Error in model.frame.default(formula = ~yvar + X + gen + block, data = list( : variable lengths differ (found for 'gen') # similar error Question 2: How can get I covariance matrix between X1 and X2 either using lme4 or lmer. X1X2 X1 Var (X1) Cov(X1,X2) X2 Cov(X1, X2) Var(X2) Should I put gen in the model to do this? Should I specify something in * correlation* = Thank you for your time Maya [[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] covariance matrix
Hi all, I generated a covariance matrix and visualized as a 2D contour plot (x,y, covariance matrix), I would like to extract from the matrix the values ( in x and y) that auto-correlate which I will plot as an normal (x,y(being the values that auto-corelate to a certain x and y values in my original matrix). Any suggestions? Cheers, Marcelo -- Marcelo Andrade de Lima UNIFESP - Universidade Federal de São Paulo Departamento de Bioquímica Disciplina de Biologia Molecular Rua Três de Maio 100, 4 andar - Vila Clementino, 04044-020 Lab +55 11 55764438 R.1188 Cell +55 11 92725274 ml...@unifesp.br [[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] covariance matrix
Dear all, I generated a covariance matrix and I would like to generate a 1D plot of the data that auto-correlate. any suggestions? Thanks, Marcelo -- Marcelo Andrade de Lima UNIFESP - Universidade Federal de São Paulo Departamento de Bioquímica Disciplina de Biologia Molecular Rua Três de Maio 100, 4 andar - Vila Clementino, 04044-020 Lab +55 11 55764438 R.1188 Cell +55 11 92725274 ml...@unifesp.br [[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] covariance matrix
Unintelligible -- to me anyway. You will have to explain what you mean more explicitly and with greater clarity -- at least for my feeble mind-- to get help. -- Bert Gunter On Fri, Oct 22, 2010 at 11:01 AM, Marcelo Lima mlim...@gmail.com wrote: Dear all, I generated a covariance matrix and I would like to generate a 1D plot of the data that auto-correlate. any suggestions? Thanks, Marcelo -- Marcelo Andrade de Lima UNIFESP - Universidade Federal de São Paulo Departamento de Bioquímica Disciplina de Biologia Molecular Rua Três de Maio 100, 4 andar - Vila Clementino, 04044-020 Lab +55 11 55764438 R.1188 Cell +55 11 92725274 ml...@unifesp.br [[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. -- Bert Gunter Genentech Nonclinical Biostatistics __ 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] covariance matrix structure for random effect in glmmPQL
Dear all, I'm using R function glmmPQL in MASS package for generalized linear mixed model considering the temporal correlations in random effect. There are 1825 observations in my data, in which the random effect is called Date, and there are five levels in Date, each repeats 365 times. When I tried fit.model1=glmmPQL(y~f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14+f15+f16+f17+f18+f19+f20+f21+f22+f23+f24, family=poisson,random=~1|Date,data=mydata,correlation=corCompSymm(value=0.2,form=~1|Date)), the model was fitted well. But because of my particular interest, I need to specify the correlation structure by myself, so I tried the following code, fit.model2=glmmPQL(y~f1+f2+f3+f4+f5+f6+f7+f8+f9+f10+f11+f12+f13+f14+f15+f16+f17+f18+f19+f20+f21+f22+f23+f24,family=poisson,random=~1|Date,data=mydata,correlation=corSymm(value=B[lower.tri(B)],form=~1|Date)), where B is a 365*365 correlation matrix that's specified by me. Then there's an error message Error in vector(double, length) : vector size specified is too large. Even I wrote B exactly the same as the one used in model1, i.e. diagonal elements 1, off-diagonal elements 0.2, the same error message shows. Is this error something inherited from the glmmPQL function that I couldn't change, or something wrong I made so that I could make certain modifications? Thanks so much in advance for any kind help! -- Best, Vicky [[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] COVARIANCE MATRIX FOR RANDOM EFFECTS - nlme
R-Help, I been using nlme to fit a model with 2 random effects. The correlation matrix I get with the VarCorr command does not seem to have the correct value for the correlation entry. E.g., below is a VarCorr matrix of random effects from data that I am working on: Variance StdDev Corr b1 14.386191885 3.79291338 b1 b30.002872538 0.05359606 0.109 Residual 0.052819504 0.22982494 The Corr value 0.109 does not appear to be correct. SAS gives a Corr value that is the square of the value got in R. I get nonsensical results when I use the value given by R. Could someone check this out. Charles O. Sabatia [[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] Covariance matrix
Hi all, Assume I have a random vector with four variables, i.e. A=(a,b,c,d). I am able to get the covariance matrix of vector A, but how can I get the covariance matrix of vector B=(a,c,b,d) by manipulating the corresponding covariance matrix of A? Thanks. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED]mailto:[EMAIL PROTECTED] [[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] Covariance matrix
Just interchange rows 2 and 3 and then columns 2 and 3 of the original covariance matrix. --- On Fri, 8/8/08, Zhang Yanwei - Princeton-MRAm [EMAIL PROTECTED] wrote: From: Zhang Yanwei - Princeton-MRAm [EMAIL PROTECTED] Subject: [R] Covariance matrix To: r-help@r-project.org r-help@r-project.org Received: Friday, 8 August, 2008, 12:18 AM Hi all, Assume I have a random vector with four variables, i.e. A=(a,b,c,d). I am able to get the covariance matrix of vector A, but how can I get the covariance matrix of vector B=(a,c,b,d) by manipulating the corresponding covariance matrix of A? Thanks. Sincerely, Yanwei Zhang Department of Actuarial Research and Modeling Munich Re America Tel: 609-275-2176 Email: [EMAIL PROTECTED]mailto:[EMAIL PROTECTED] [[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] covariance matrix of the regression coefficients
Greetings, Cohen, Cohen, West, and Aiken 2003 (Applied Multiple Regression-Correlation Analysis for the Behavioral Sciences, Third Edition) on page 273 state the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How can it be calculated with R. Thank you very much. pbm Peter B. Mandeville cel:444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2350 P.D. Favor de confirmar la llegada de este correo. Gracias. [[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] covariance matrix of the regression coefficients
Greetings, Cohen, Cohen, West, and Aiken 2003 (Applied Multiple Regression-Correlation Analysis for the Behavioral Sciences, Third Edition) on page 273 state the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How can it be calculated with R. Thank you very much. pbm Peter B. Mandeville cel:444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2350 P.D. Favor de confirmar la llegada de este correo. Gracias. [[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] covariance matrix of the regression coefficients
Greetings, On page 273, Cohen, Cohen, West, and Aiken (Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences, Third Edition, state that the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How does one calculate the matrix in R. Thank you very much. pbmPeter B. Mandeville cel: 444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2352 P.D. Favor de confirmar la llegada de este correo. Gracias. _ [[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] covariance matrix of the regression coefficients
?vcov You can use vcov(lm.obj) to extract the covariance matrix, where lm.obj is your fitted object from lm(). Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter B. Mandeville Sent: Monday, October 29, 2007 1:30 PM To: r-help@r-project.org Subject: [R] covariance matrix of the regression coefficients Greetings, Cohen, Cohen, West, and Aiken 2003 (Applied Multiple Regression-Correlation Analysis for the Behavioral Sciences, Third Edition) on page 273 state the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How can it be calculated with R. Thank you very much. pbm Peter B. Mandeville cel:444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2350 P.D. Favor de confirmar la llegada de este correo. Gracias. [[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] covariance matrix of the regression coefficients
See ?vcov . On Mon, 29 Oct 2007, Peter B. Mandeville wrote: Greetings, Cohen, Cohen, West, and Aiken 2003 (Applied Multiple Regression-Correlation Analysis for the Behavioral Sciences, Third Edition) on page 273 state the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How can it be calculated with R. Thank you very much. pbm Peter B. Mandeville cel:444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2350 P.D. Favor de confirmar la llegada de este correo. Gracias. [[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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] covariance matrix of the regression coefficients
Peter B. Mandeville wrote: Greetings, Cohen, Cohen, West, and Aiken 2003 (Applied Multiple Regression-Correlation Analysis for the Behavioral Sciences, Third Edition) on page 273 state the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How can it be calculated with R. Thank you very much. pbm help.search(covariance) points you at vcov() soon enough -- 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 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] covariance matrix of the regression coefficients
If X is your p-1 variable matrix (with the first column vector being 1s), i.e., nrow(X)=n and ncol(X)=p then MSE-summary(lm(Y~X[2]+X[3] + ...X[P-1]))$s^2 and your coefficient (co)variance matrix is MSE*ginv(t(X)%*%X) Best, Alex On 10/29/07, Peter B. Mandeville [EMAIL PROTECTED] wrote: Greetings, On page 273, Cohen, Cohen, West, and Aiken (Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences, Third Edition, state that the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How does one calculate the matrix in R. Thank you very much. pbmPeter B. Mandeville cel: 444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2352 P.D. Favor de confirmar la llegada de este correo. Gracias. _ [[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. -- *** A. Alexander Beaujean, Ph.D., LSSP Licensed Psychologist (Provisional, TX) http://myprofile.cos.com/abeaujean http://www.baylor.edu/soe/faculty/index.php?id=38476 General impressions are never to be trusted. Unfortunately when they are of long standing they become fixed rules of life, and assume a prescriptive right not to be questioned. Consequently those who are not accustomed to original inquiry entertain a hatred and a horror of statistics. They cannot endure the idea of submitting their sacred impressions to cold-blooded verification. But it is the triumph of scientific men to rise superior to such superstitions, to devise tests by which the value of beliefs may be ascertained, and to feel sufficiently masters of themselves to discard contemptuously whatever may be found untrue. --Sir Francis Galton, FRS [[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] covariance matrix of the regression coefficients
Dear Peter, See ?vcov. You could have discovered this via help.search(covariance). I hope this helps, John On Mon, 29 Oct 2007 11:30:11 -0600 Peter B. Mandeville [EMAIL PROTECTED] wrote: Greetings, Cohen, Cohen, West, and Aiken 2003 (Applied Multiple Regression-Correlation Analysis for the Behavioral Sciences, Third Edition) on page 273 state the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How can it be calculated with R. Thank you very much. pbm Peter B. Mandeville cel:444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2350 P.D. Favor de confirmar la llegada de este correo. Gracias. [[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. John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ 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] covariance matrix of the regression coefficients
I don't think you ever want to do it this way. vcov() gives what is needed. But, if you perform matrix operations represented algebraically as t(x) %*% x, then use crossprod(x) and NOT t(x) %*% x See the paper at the link below for reasons why @ARTICLE{Rnews:Bates:2004, author = {Douglas Bates}, title = {Least Squares Calculations in {R}}, journal = {R News}, year = 2004, volume = 4, number = 1, pages = {17--20}, month = {June}, url = {http://CRAN.R-project.org/doc/Rnews/}, pdf = {http://CRAN.R-project.org/doc/Rnews/Rnews_2004-1.pdf} } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of A. Beaujean Sent: Monday, October 29, 2007 4:25 PM To: Peter B. Mandeville Cc: r-help Subject: Re: [R] covariance matrix of the regression coefficients If X is your p-1 variable matrix (with the first column vector being 1s), i.e., nrow(X)=n and ncol(X)=p then MSE-summary(lm(Y~X[2]+X[3] + ...X[P-1]))$s^2 and your coefficient (co)variance matrix is MSE*ginv(t(X)%*%X) Best, Alex On 10/29/07, Peter B. Mandeville [EMAIL PROTECTED] wrote: Greetings, On page 273, Cohen, Cohen, West, and Aiken (Applied Multiple Regression/Correlation Analysis for the Behavioral Sciences, Third Edition, state that the covariance matrix of the regression coefficients is provided by standard programs for multiple regression, including SAS, SPSS, and SYSTAT. How does one calculate the matrix in R. Thank you very much. pbmPeter B. Mandeville cel: 444 860 3204 tel: 52 444 826 2346-49 ext 532 fax: 52 444 826 2352 P.D. Favor de confirmar la llegada de este correo. Gracias. _ [[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. -- *** A. Alexander Beaujean, Ph.D., LSSP Licensed Psychologist (Provisional, TX) http://myprofile.cos.com/abeaujean http://www.baylor.edu/soe/faculty/index.php?id=38476 General impressions are never to be trusted. Unfortunately when they are of long standing they become fixed rules of life, and assume a prescriptive right not to be questioned. Consequently those who are not accustomed to original inquiry entertain a hatred and a horror of statistics. They cannot endure the idea of submitting their sacred impressions to cold-blooded verification. But it is the triumph of scientific men to rise superior to such superstitions, to devise tests by which the value of beliefs may be ascertained, and to feel sufficiently masters of themselves to discard contemptuously whatever may be found untrue. --Sir Francis Galton, FRS [[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.