[R] set.cor/mat.regress

William Revelle lists at revelle.net
Thu Jan 8 05:24:36 CET 2015


Dear Andrea.


First of all, the usual advice.  If you have problems with a particular function in a particular package, first try the package author.  I just happened to find your query.

Then, to your question.



> On Jan 7, 2015, at 6:19 PM, Andrea Lamont <alamont082 at gmail.com> wrote:
> 
> I am having a problem with the function mat.regress in the psych package
> that I was hoping someone would be able to give guidance on.
> 
> I have a correlation matrix that is [76,76] with the first column
> representing the Y variable, the rest are the Xs. This is what my data
> looks like:
> 
> m=runif(5776,-1,1)
> 
> mdat <- matrix(m, nrow = 76, ncol = 76, byrow = TRUE)
> 
> diag(mdat) <- 1

The matrix you are forming is of course, not a correlation matrix, for you are just making up random values in  76 x 76 matrix with a diagonal of 1. The matrix is not symmetric.

For a known correlation matrix, e.g., the Thurstone 9 abilities:

 set.cor(y=1,x=c(2:9),data=Thurstone)

This works as documented, that is, it finds the beta weights for the 8 predictors (variables 2:9) to predict the first variable. 


I am not sure what you are doing wrong.  You could send me as a rda file the matrix you are trying to analyze and I can see if I can see the problem.

You might also run
sessionInfo()  to give me a little more help.

Bill




> 
> 
> I am trying to obtain beta weights/regression coefficients from this
> correlation matrix.
> 
> When I run:
> 
> set.cor(y=1, x=c(2:76),data=mdat)
> 
> or mat.regrss(y=1, x=c(2:76),data=mdat)  
This definitely will not work since the function is mat.regress


> 
> 
> I get odd errors.  Most recently:
> 
> set.cor(y=1, x=c(2:76),data=mdat) yields
> 
> Error in array(x, c(length(x), 1L), if (!is.null(names(x))) list(names(x),
> :
> 
>  'data' must be of a vector type, was 'NULL'
> 
> I have tried converting my matrix to a vector (as.vector). Still got
> errors. Another common error I am getting is that the subscript not being
> bound. I tried other options like square=FALSE to no avail.
> 
> It seems like such a straightforward function, I'm not sure what I'm doing
> wrong.
> 
> 
> Any help is appreciated.
> 
> Thanks
> 
> Andrea
> 
> -- 
> Andrea Lamont, PhD
> Post-Doctoral Fellow
> University of South Carolina
> Columbia, SC 29208
> 
> *Please consider the environment before printing this email.*
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
> 

William Revelle		           http://personality-project.org/revelle.html
Professor			           http://personality-project.org
Department of Psychology   http://www.wcas.northwestern.edu/psych/
Northwestern University	   http://www.northwestern.edu/
Use R for psychology             http://personality-project.org/r
It is 5 minutes to midnight	   http://www.thebulletin.org



More information about the R-help mailing list