Re: [R] Help on how to use cosinor analysis
Dear Friday, You need to specify what package you are using. There is a package (cosinor) that is meant for doing this. In addition, the psych package has a cosinor function, as do the CircStats and circular packages. For your data, you need to use the c() function library(psych) Time=c(1,2,3,4,24) #add more times Rectal=c(33.8,37.6,37.1,35.5,38.2) #add more temperatures cosinor(Time,Rectal) Then, to plot these, you will need to form a data frame timeTemp <- data.frame(Time,Rectal) cosinor.plot("Time","Rectal",data=timeTemp) > On Dec 23, 2015, at 7:45 AM, friday zakari <fridayzak...@gmail.com> wrote: > > l am a beginner in the use of R for statistical analysis. I am finding it > difficult to use cosinor to analyze the circadian rhythm in rectal > temperature in broiler chicken. > > Time=(1,2,3,4.24) > Rectal temp=(33.8,37.6,37.1,35.5,..38.2) > > l will be very please if you can guide me on how to do the analysis using > the sets of variables above as example and if you can also assist me with > the R functions required for the analysis. thank you very much > > [[alternative HTML version deleted]] > > __ > R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 3 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] Phi coefficient matrix (package psych)
Kumar and Jim, The phi coefficient is identical to the Pearson coefficient in the case of a 2 x 2 data set. As it says in the help file for phi: Since the phi coefficient is just a Pearson correlation applied to dichotomous data, to find a matrix of phis from a data set involves just finding the correlations using cor or lowerCor or corr.test.” So, you can do a cor(df) and you do not need the phi(df) If you want the tetrachoric (which estimates what a Pearson would be if you had not artificially dichotomized the data) try tetrachoric(df) Bill On Apr 21, 2015, at 3:34 PM, Kumar Mainali kpmain...@gmail.com wrote: I want to calculate phi coefficient for every pair of the columns. Is there a way to generate a matrix like a correlation matrix? I know cor function in the case below gives same answer as phi coefficient. x - sample(c(0,1), 10, replace=TRUE) y - sample(c(0,1), 10, replace=TRUE) z - sample(c(0,1), 10, replace=TRUE) df - data.frame(x,y,z) cor(df) library(psych) phi(df) Thank you, Kumar Mainali Postdoctoral Associate Department of Biology University of Maryland ᐧ [[alternative HTML version deleted]] __ R-help@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 Professorhttp://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 3 minutes to midnight http://www.thebulletin.org William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 3 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] PCA analysis and bootstraped loadings
psych does not currently have bootstrapped confidence intervals for loadings. That is a reasonable request and I will try to add it, perhaps in the “real soon now” version of 1.5.4 (almost finished), perhaps in the next release, Bill On Apr 13, 2015, at 2:38 PM, stephen sefick ssef...@gmail.com wrote: Hi, Please search the mailing list archives for this, or type bootstrapped PCA R into google. Please provide a minimal self-contained example of what you are trying to solve. Please read the posting guide that is referenced at the end of every email. kind regards, Stephen On Mon, Apr 13, 2015 at 11:07 AM, Efstathia Defteraiou efstathia.deftera...@student.uibk.ac.at wrote: Dear All, I am relatively new in R. Im working with the 'psych' package and 'principal' function. I would like to know how to generate the bootstraped conf.intervals for loadings, looking for sth similar to setting 'n.iter' argument for the 'fa' function. If in 'psych' can't work and suggest me the 'boot' package please provide specific Rscript since I don't understand the commands and arguments that have to be used before calling the function 'boot'( what are indices? what to define as what inside function(){}) The names Im using are included in the following code: 'newdata3.1' is my data and provided as data.frame makingtheanalysis3.1 -principal(newdata3.1, nfactors =3, residuals = FALSE, covar=FALSE,rotate=varimax,scores=TRUE) I am sorry for not providing a specific code but my data are too large Any Help appreciated Cheers! __ R-help@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. -- Stephen Sefick ** Auburn University Biological Sciences 331 Funchess Hall Auburn, Alabama 36849 ** sas0...@auburn.edu http://www.auburn.edu/~sas0025 ** Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis A big computer, a complex algorithm and a long time does not equal science. -Robert Gentleman [[alternative HTML version deleted]] __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 3 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] Extracting Factor Pattern Matrix Similar to Proc Factor
David and Scott, principal will also take a covariance matrix (set the cover option to TRUE) library(psych) C - cov(iris[-5]) pc4 - principal(C,4,covar=TRUE,rotate=none”) However, in the case of no rotation or orthogonal rotations, the structure matrix and the pattern matrix are identical. They differ only if you take an oblique solution. So, pc4 #will give you the results print(pc4$loadings,cutoff=0) #will give the loadings (pattern) print(pc4$Structure,cutoff=0) #will give the structure matrix If the input is a covariance matrix, and you want to do the analysis on the correlation matrix, principal does that automatically. C - cov(iris[-5]) pc4 - principal(C,4,rotate=none”) pc4 Bill On Feb 23, 2015, at 3:58 PM, David L Carlson dcarl...@tamu.edu wrote: Function principal() in psych takes a correlation matrix so use cov2cor() to convert: library(psych) iris.pca - principal(cov2cor(cov(iris[,-5])), nfactors=4, rotate=none) print(iris.pca$Structure, cutoff=0) David -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Scott Colwell Sent: Monday, February 23, 2015 3:34 PM To: r-help@r-project.org Subject: Re: [R] Extracting Factor Pattern Matrix Similar to Proc Factor Thanks David. What do you do when the input is a covariance matrix rather than a dataset? -- View this message in context: http://r.789695.n4.nabble.com/Extracting-Factor-Pattern-Matrix-Similar-to-Proc-Factor-tp4703704p4703719.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 3 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] 2d rotation: vegan?
Randall, You might try the factor.rotate function in the psych package. That will allow you to “hand rotate” any solution where (in your example) nmdp is a matrix. You also could look at the the various rotations available in the GPArotation package. Bill On Feb 13, 2015, at 9:08 AM, Randall Morris-Ostrom randall.morrisost...@icloud.com wrote: I've been working at interpreting the results of a non-metric multidimensional scaling analysis. I have been using metaMDS in the vegan package because one of the benefits is that it also rotates to solution to its principal components. (Eventually I realized that there is no reason why my results would be most interpretable when aligned along the PC, but it was a nice starting point.) I have been trying to find ways to rotate the resulting plot so I can visualize it differently and look at actual plot positions (as opposed to just rotating the print outs I have been looking at.) I'm able to find lots of suggestions for how to rotate3d plots, but almost nothing for 2d. I have tried using the MDSrotate function in vegan, but really it comes down to the fact that I'm clueless when I try to make sense of the documentation. *somewhat embarrassed* My goal is basically to rotate the plot and exam the structure as a tool to generate theories about the meaning of the different dimensions (the interpretation of the clusters in my research are crystal clear.) I generated a little fake data, just so there would be a plot. I've been trying to figure out how to do this as either just a simple scatterplot or using the vegan package. Thank you for your time, Randy Randall Morris-Ostrom J.D., M.S. Doctoral Candidate in Psychology, University of St. Thomas randall.morrisost...@icloud.com Sample Code library(vegan) set.seed(12345) x - rnorm(1:10) y - rnorm(1:10) df - data.frame(x,y) d - dist(df, method = euclidean) nmds - metaMDS(df, distance = euclidean, k = 2) plot(nmds) # or nmdp - as.data.frame(nmds$points) plot(nmdp$MDS1, nmdp$MDS2) [[alternative HTML version deleted]] __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 3 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] How to add error bars to a line xyplot (lattice package)
You might want to look at the examples in error.bars.by in the psych package. Bill On Jan 26, 2015, at 7:58 PM, Jun Shen jun.shen...@gmail.com wrote: Dear list, I have a couple of lines (superimposed) in an xyplot and just want to add error bars to each of the data point. It's been a while since this question was asked last time. But the segplot from latticeExtra is not straight forward. Just wonder if there is a better way to do this. Appreciate for any comment. Thanks. Jun [[alternative HTML version deleted]] __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 3 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] Psych package: why am I receiving NA for many of the factor scores?
Dear Elizabeth, A correction to my suggestion: scaled - scale(mydata) wts - f4$weights scores -t( apply(scaled,1,function(x) colSums(x*wts,na.rm=TRUE))) #you need the colSums not the sum function Also, your confusion in getting the NAs with missing data was due to a bug in the fa function in the way it just ignored the missing statement. Thanks for catching that. It is now fixed and should be on CRAN real soon. Bill On Jan 14, 2015, at 9:39 AM, William Revelle li...@revelle.net wrote: Dear Elizabeth, Factor scores in the fa function are found by multiplying the standardized data by the factor weights using matrix multiplication. This will give scores only for subjects with complete data. However, if you want, you can create them yourself by standardizing your data and then multiplying them by the weights: mydata - rProjectSurveyDataJustVariables f4 - fa(my.data,4) #modify this to match your call wts - f4$wts scaleddata - scale(mydata) scores - apply(scaleddata,1,function(x) sum(x * wts,na.rm=TRUE)) #this will work with complete data, and impute factor scores for those cases with incomplete data. If the data are missing completely at random, this should give a reasonable answer. However, if the missingness has some structure to it, the imputed scores will be biased. This is a reasonable option to add to the fa function and I will do so. A side note. If you need help with a package, e.g., psych, you get faster responses by writing to the package author. I just happened to be browsing R-help when your question came in. Let me know if this solution works for you. Bill On Jan 13, 2015, at 7:46 PM, Elizabeth Barrett-Cheetham ebarrettcheet...@gmail.com wrote: Hello R Psych package users, Why am I receiving NA for many of the factor scores for individual observations? I'm assuming it is because there is quite a bit of missing data (denoted by NA). Are there any tricks in the psych package for getting a complete set of factor scores? My input is: rProjectSurveyDataJustVariables = read.csv(R Project Survey Data Just Variables.csv, header = TRUE) solution - fa(r = rProjectSurveyDataJustVariables, nfactors = 4, rotate = oblimin, fm = ml, scores = tenBerge, warnings = TRUE, oblique.scores = TRUE) solution Thank you. __ R-help@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 Professorhttp://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 __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] Psych package: why am I receiving NA for many of the factor scores?
Dear Elizabeth, Factor scores in the fa function are found by multiplying the standardized data by the factor weights using matrix multiplication. This will give scores only for subjects with complete data. However, if you want, you can create them yourself by standardizing your data and then multiplying them by the weights: mydata - rProjectSurveyDataJustVariables f4 - fa(my.data,4) #modify this to match your call wts - f4$wts scaleddata - scale(mydata) scores - apply(scaleddata,1,function(x) sum(x * wts,na.rm=TRUE)) #this will work with complete data, and impute factor scores for those cases with incomplete data. If the data are missing completely at random, this should give a reasonable answer. However, if the missingness has some structure to it, the imputed scores will be biased. This is a reasonable option to add to the fa function and I will do so. A side note. If you need help with a package, e.g., psych, you get faster responses by writing to the package author. I just happened to be browsing R-help when your question came in. Let me know if this solution works for you. Bill On Jan 13, 2015, at 7:46 PM, Elizabeth Barrett-Cheetham ebarrettcheet...@gmail.com wrote: Hello R Psych package users, Why am I receiving NA for many of the factor scores for individual observations? I'm assuming it is because there is quite a bit of missing data (denoted by NA). Are there any tricks in the psych package for getting a complete set of factor scores? My input is: rProjectSurveyDataJustVariables = read.csv(R Project Survey Data Just Variables.csv, header = TRUE) solution - fa(r = rProjectSurveyDataJustVariables, nfactors = 4, rotate = oblimin, fm = ml, scores = tenBerge, warnings = TRUE, oblique.scores = TRUE) solution Thank you. __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] Question about package principal
As David suggests, look at your data. For instance, there seems to be only 1 case (#2) for seat.width.club with non-zero data. I find it hard to believe that the other planes have seat.widths of 0! I think you probably want to code the 0s as missing, rather than 0. You also want to rethink the variables since some of them are almost completely missing. At least 3 of your variables are completely collinear (they correlate 1.0 to 5 decimals) Seat.width and pitch in club all correlate 1.0. On Jan 11, 2015, at 1:59 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 11, 2015, at 3:55 AM, 오건희 wrote: Hi, I tried to run principal function in the 'psych' package, but it failed to do.. here is both my code and error message. I searched on the web, but couldn't find the exact answer I wanted. data-read.csv( https://raw.githubusercontent.com/mylesmharrison/delta_PCA_kmeans/master/delta.csv ,row.names=1) airpca-principal(data,nfactors=33,rotate=none) Error in solve.default(model, r) : system is computationally singular: reciprocal condition number = 7.05776e-17 In addition: Warning messages: 1: In cor.smooth(model) : Matrix was not positive definite, smoothing was done 2: In cor.smooth(r) : Matrix was not positive definite, smoothing was done Looks like your data is highly correlated in some of those columns: dat[[1]] [1] 0.0 19.4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 [25] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 dat[[29]] [1] 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 dat[[2]] [1] 0 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [42] 0 0 0 dat[[3]] [1] 0 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [42] 0 0 0 I'd retry after removing the problem columns. Thank you for your help. [[alternative HTML version deleted]] __ R-help@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. David Winsemius Alameda, CA, USA __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] set.cor/mat.regress
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 alamont...@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@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] Difference in cummulative variance depending on print command
Dear Rena, As Peter points out, it is better to ask the maintainer of the program for detailed questions. As Peter correctly surmised, print.psych (which is used to print the output from the fa function), knows that you have an oblique solution and is reporting the amount of variance associated with the oblique factors (taking into account that they are correlated). The default print method assumes orthogonal factors. If you compare the total amount of variance accounted for (cumulative Var) for all of the factors (.59) , this will match that found using orthogonal rotations, while the default print method of the loadings does not. Bill On Dec 6, 2014, at 10:48 AM, peter dalgaard pda...@gmail.com wrote: Firstly, there is no fa() function in base R. There is one in package psych(), which has a maintainer, etc. I guess that it is because fa() does a non-orthogonal factor rotation and its print method knows about it, whereas the default print method for loadings assumes that rotations are orthogonal. - Peter D. On 05 Dec 2014, at 13:28 , Rena Büsch rena.bue...@gmx.de wrote: Hello, I am trying a factor analysis via R. When running the pricipal axis analysis I do get different tables depending on the print command. This is my factor analysis: fa.pa_cor_3_2- fa(ItemsCor_4, nfactors=3, fm=pa,rotate=oblimin) To get the h2 I did the following print command: print (fa.pa_cor_3_2, digits=2, cut=.3, sort=T) To just get the loadings I did the following print command: print (fa.pa_cor_3_2$loadings, digits=2, cutoff=.3, sort=T) The result of the first print is the following Eigenvalue-cumulative variance table: PA1 PA2 PA3 SS loadings20.59 18.16 5.03 Proportion Var 0.28 0.25 0.07 Cumulative Var 0.28 0.52 0.59 With the second print command I get a different table: PA1 PA2 PA3 SS loadings17.63 15.12 3.14 Proportion Var 0.24 0.20 0.04 Cumulative Var 0.24 0.44 0.49 The loadings are the same for both commands. There is just this slight difference in the cumulative Var. Does anyone have an idea of a cause for the difference? What can I report? Did I post enough information to fully understand my problem? Thanks in Advance Rena __ R-help@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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@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 Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ R-help@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.
Re: [R] simulation data with dichotomous varuables
Dear Thanoon, You might look at the various item simulation functions in the psych package. In particular, for your problem: R1 - sim.irt(10,1000,a=3,low = -2, high=2) R2 - sim.irt(10,1000,a=3,low = -2, high=2) R12 - data.frame(R1$items,R2$items) #this gives you 20 items, grouped with high correlations within the first 10, and the second 10, no correlation between the first and second sets. rho - tetrachoric(R12)$rho #find the tetrachoric correlation between the items lowerMat(rho) #show the correlations cor.plot(rho,numbers=TRUE) #show a heat map of the correlations Bill On Aug 4, 2014, at 8:08 PM, thanoon younis thanoon.youni...@gmail.com wrote: Dear R-users i need your help to solve my problem in the code below, i want to simulate two different samples R1 and R2 and each sample has 10 variables and 1000 observations so i want to simulate a data with high correlation between var. in R1 and also in R2 and no correlation between R1 and R2 also i have a problem with correlation coefficient between tow dichotomous var. the R- program supports just these types of correlation coefficients such as pearson, spearman,kendall. thanks alot in advance Thanoon ords - seq(0,1) p - 10 N - 1000 percent_change - 0.9 R1 - as.data.frame(replicate(p, sample(ords, N, replace = T))) R2 - as.data.frame(replicate(p, sample(ords, N, replace = T))) # pearson is more appropriate for dichotomous data cor(R1, R2, method = pearson) # subset variable to have a stronger correlation v1 - R1[,1, drop = FALSE] v1 - R2[,1, drop = FALSE] # randomly choose which rows to retain keep - sample(as.numeric(rownames(v1)), size = percent_change*nrow(v1)) change - as.numeric(rownames(v1)[-keep]) # randomly choose new values for changing new.change - sample(ords, ((1-percent_change)*N)+1, replace = T) # replace values in copy of original column v1.samp - v1 v1.samp[change,] - new.change # closer correlation cor(v1, v1.samp, method = pearson) # set correlated column as one of your other columns R1[,2] - v1.samp R2[,2] - v1.samp R1 R2 [[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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Is there a package for EFA with multiple groups?
Dear Josh and Elizabeth, Josh suggested one way of doing it with the psych package. As of today, the psych package (version psych_1.4.8) , I have included a new function (faBy) that will work with the statsBy function to do EFA for each of multiple groups. Basically, it just calls the statsBy function to get correlations for each subgroup, and then applies fa to that output. Thus, sb - statsBy(data, group=“grouping variable”,cors=TRUE) fb - faBy(sb,nfactors= how ever many you want) This version is working its way through the CRAN distribution channels, but can be obtained from the personality-project repository at http://personality-project.org/r/ (if using a Mac) or http://personality-project.org/r/src/contrib/ if using a PC. Look for version 1.4.8 Bill On Jul 28, 2014, at 5:22 AM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi Elizabeth, In confirmatory factor analysis with multiple groups, the reason one needs to estimate the models simultaneously is that, typically, one is interested in applying constraints (e.g., forcing all or some of the factor loadings to be equal across groups). In exploratory factor analysis, constraints are uncommon (they are somewhat un-exploratory). I would suggest simply using the psych package and subsetting your data to the particular group, as in: efa( data = subset(data, Group == Group1) ) efa( data = subset(data, Group == Group2) ) etc. As you noted, lavaan will allow you to test multiple group CFAs, so if/when you are ready to see whether the same configural factor structure or any other level of invariance holds across your groups, you can use it. Sincerely, Josh On Mon, Jul 28, 2014 at 2:46 PM, Elizabeth Barrett-Cheetham ebarrettcheet...@gmail.com wrote: Hello R users, I’m hoping to run an exploratory and confirmatory factor analysis on a psychology survey instrument. The data has been collected from multiple groups, and it’s likely that the data is hierarchical/has 2nd order factors. It appears that the lavaan package allows me to run a multiple group hierarchical confirmatory factor analysis. Yet, I can’t locate a package that can run the equivalent exploratory analysis. Could anyone please direct me to an appropriate package? Many thanks, Elizabeth __ 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. -- Joshua F. Wiley Ph.D. Student, UCLA Department of Psychology http://joshuawiley.com/ Senior Analyst, Elkhart Group Ltd. http://elkhartgroup.com Office: 260.673.5518 [[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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Principal component analysis with EQUAMAX rotation
Dear Orvalo Augusto, If you are using a PC, you need to get the zip file, not the tar.gz file. It is at http://personality-project.org/r/src/contrib/ For Macs it is an “other repository” (source option) at http://personality-project.org/r/ Bill On Jun 21, 2014, at 12:36 AM, Orvalho Augusto orvaq...@gmail.com wrote: Dear! I get this error when I try to install it on my linux PC: root@orvaquimcism:~# R CMD INSTALL /mnt/disco/downloads/R/psych_1.4.6.20.tar.gz Error in rawToChar(block[seq_len(ns)]) : embedded nul in string: '\037\x8b\b\0\0\0\0\0\0\003\xec\xbdk{\xe3Ƒ(\x9c\xaf\xc2\xf3\xf0?\xb4\xa9I\x86\x90 \x8a\0uq\xbc\x86\xf3N\xb1\xd79\xb6ck\xc6\xde=\xab(\xfb@$$\xc1C\0024@J\x94gy~\xfb[\xb7\xbe\0\004%\xcdxf\xe2d5\x89E\xa0\xd1]}\xab\xae\xae\xaa\xae\xae\x9aU\xb7\xa3\xab\xfd?\xfd\xf9\xc5\xf3' My PC is: Xubuntu 12.04 64-bit with R version 3.1.0 (2014-04-10). Thanks Orvalho On Fri, Jun 20, 2014 at 6:36 PM, William Revelle li...@revelle.net wrote: Dear Wagner, I added the equamax rotation option to the psych package in version 1.4.6. This was requested by Sagnik Chakravarty, with a solution by Gunter Nickel. Unfortunately, the version on CRAN is 1.4.5, but you can get the working prerelease of 1.4.6 (1.4.6.20) from the alternate repository http://personality-project.org/r/ (if using a Mac) or http://personality-project.org/r/src/contrib/ if using a PC. Thus, p3e - principal(Thurstone,3,rotate=equamax) #will extract the first three components and rotate them using equamax. p3n - principal(Thurstone,3,rotate=none) #will give you the unrotated 3 component solution p3v - principal(Thurstone,3,rotate=varimax) #for the varimax solution factor.congruence(list(p3e,p3n,p3v)) #compares the Burt/Tucker congruence coefficients for these three solutions Let me know if this does what you want. Bill On Jun 19, 2014, at 2:07 AM, Wagner wagner@gmx.de wrote: Hello, I need to do a principal component analysis with EQUAMAX-rotation. Unfortunately the function principal() I use normally for PCA does not offer this rotation specification. I could find out that this might be possible somehow with the package GPArotation but until now I could not figure out how to use this in the principal component analysis. Maybe someone can give an example on how to do an equamax-rotation PCA? Or is there a function in another package that offers the use of equamax-rotation directly? Thank you for your help! -- View this message in context: http://r.789695.n4.nabble.com/Principal-component-analysis-with-EQUAMAX-rotation-tp4692337.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Principal component analysis with EQUAMAX rotation
Dear Wagner, I added the equamax rotation option to the psych package in version 1.4.6. This was requested by Sagnik Chakravarty, with a solution by Gunter Nickel. Unfortunately, the version on CRAN is 1.4.5, but you can get 1.4.6 from the alternate repository http://personality-project.org/r/ (if using a Mac) or http://personality-project.org/r/src/contrib/ if using a PC. Thus, p3 - principal(Thurstone,3,rotate=equamax”) #will extract the first three components and rotate them using equamax. Let me know if this does what you want. Bill On Jun 19, 2014, at 2:07 AM, Wagner wagner@gmx.de wrote: Hello, I need to do a principal component analysis with EQUAMAX-rotation. Unfortunately the function principal() I use normally for PCA does not offer this rotation specification. I could find out that this might be possible somehow with the package GPArotation but until now I could not figure out how to use this in the principal component analysis. Maybe someone can give an example on how to do an equamax-rotation PCA? Or is there a function in another package that offers the use of equamax-rotation directly? Thank you for your help! -- View this message in context: http://r.789695.n4.nabble.com/Principal-component-analysis-with-EQUAMAX-rotation-tp4692337.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Principal component analysis with EQUAMAX rotation
Dear Wagner, I added the equamax rotation option to the psych package in version 1.4.6. This was requested by Sagnik Chakravarty, with a solution by Gunter Nickel. Unfortunately, the version on CRAN is 1.4.5, but you can get the working prerelease of 1.4.6 (1.4.6.20) from the alternate repository http://personality-project.org/r/ (if using a Mac) or http://personality-project.org/r/src/contrib/ if using a PC. Thus, p3e - principal(Thurstone,3,rotate=equamax) #will extract the first three components and rotate them using equamax. p3n - principal(Thurstone,3,rotate=none) #will give you the unrotated 3 component solution p3v - principal(Thurstone,3,rotate=varimax) #for the varimax solution factor.congruence(list(p3e,p3n,p3v)) #compares the Burt/Tucker congruence coefficients for these three solutions Let me know if this does what you want. Bill On Jun 19, 2014, at 2:07 AM, Wagner wagner@gmx.de wrote: Hello, I need to do a principal component analysis with EQUAMAX-rotation. Unfortunately the function principal() I use normally for PCA does not offer this rotation specification. I could find out that this might be possible somehow with the package GPArotation but until now I could not figure out how to use this in the principal component analysis. Maybe someone can give an example on how to do an equamax-rotation PCA? Or is there a function in another package that offers the use of equamax-rotation directly? Thank you for your help! -- View this message in context: http://r.789695.n4.nabble.com/Principal-component-analysis-with-EQUAMAX-rotation-tp4692337.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] plot in package psych with function error.bars.by
Dear Tham, The example you were running was filtering out the subjects less than 10 years old and more than 80. Somehow you suppressed this filtering which lead to the error message. The filtering was done to avoid the problem you detected. I have fixed error.bars.by so that it now will just complain if there is only one case (and thus no error) in a cell. In this case, it will not draw the “cats eye” error bars. The Mac version of psych_1.4.6.18 is now on the personalty.project.org/r server repository. The PC version is at personality-project/r/src/contrib/ as a zip file: psych_1.4.6.18.zip For a Mac, just set your other repository to personalty.project.org/r and install the source version. For a PC you need to ftp or http to personality-project/r/src/contrib/ to get the zip file. Once again, when you discover a problem with the psych package, make sure to write me directly as well as the list. You will get much faster turnaround. Bill On Jun 16, 2014, at 2:52 AM, Tham Tran hanhtham.t...@yahoo.com.vn wrote: Hi William, I've just updated your latest package psych_1.4.6.11.zip from server personality-project/r/src/contrib/. One time the updating process was finished, i tried to run based samples code: require(psych) keys.list=list(Agree=c(-1,2:5),Conscientious=c(6:8,-9,-10),Extraversion=c(-11,-12,13:15),Neuroticism=c(16:20),Openness = c(21,-22,23,24,-25)) keys = make.keys(28,keys.list,item.labels=colnames(bfi)) scores = scoreItems(keys,bfi,min=1,max=6) error.bars.by(scores$scores,round(bfi$age/10)*10,by.var=TRUE,main=BFI age trends,legend=3,labels=colnames(scores$scores),xlab=Age,ylab=Mean item score) then i had an error following: Erreur dans if (del == 0 to == 0) return(to) : valeur manquante là où TRUE / FALSE est requis De plus : Messages d'avis : 1: In qt(1 - alpha/2, group.stats[[g]]$n - 1) : production de NaN 2: In dt(ln, n - 1) : production de NaN 3: In qt(alpha/2, n - 1) : production de NaN Could you tell me how to fix these issues? May i had a mistake of updating your lasted package? Sincerly Tham -- View this message in context: http://r.789695.n4.nabble.com/plot-in-package-psych-with-function-error-bars-by-tp4691632p4692177.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] plot in package psych with function error.bars.by
Tham and Jim, The Mac version of psych_1.4.6.11 is now on the personalty.project.org/r server repository. The PC version is at personality-project/r/src/contrib/ as a zip file: psych_1.4.6.11.zip For a Mac, just set your other repository to personalty.project.org/r and install the source version. For a PC you need to ftp or http to personality-project/r/src/contrib/ to get the zip file. This partially fixes the pch request from Tham. (That is to say, you can set the first pch. The others are just the sequence above that one.). Let me know if you have problems. Bill On Jun 7, 2014, at 3:10 PM, William Revelle li...@revelle.net wrote: Tham and Jim, As usual, my first response to this is when you find a problem with the psych package, write me (as author) as well as the R-help list. In addition, always include which version of psych you are running. That will help in the debugging. The current version 1.4.5 on CRAN draws “cats eyes” instead of error bars, unless you turn off that option. You might find that useful. Then, my comment to Tham, Yes, you have found a weakness (some would say a bug) in that I currently default the base plot character to be 15. I will correct this in the next release (which won’t be shipped to CRAN until mid to late July). In the interim, I will try to get a fix up on the personality-project.org/r repository by early next week. To Jim, I can not get your error at all. Tham was finding a problem with the basic example, which works, unless you try to specify the pch, which doesn’t work. Bill On Jun 3, 2014, at 4:10 PM, Jim Lemon j...@bitwrit.com.au wrote: On Mon, 2 Jun 2014 11:28:19 PM Tham Tran wrote: Hi, I have a problem with the function error.bars.by in package psych. This is the code for example of a graph: keys.list=list(Agree=c(-1,2:5),Conscientious=c(6:8,-9,-10),Extraversion=c(-1 1,-12,13:15),Neuroticism=c(16:20),Openness = c(21,-22,23,24,-25)) keys = make.keys(28,keys.list,item.labels=colnames(bfi)) scores = score.items(keys,bfi,min=1,max=6) require(psych) error.bars.by(scores$scores,round(bfi$age/10)*10,by.var=TRUE, main=BFI age trends,legend=3,labels=colnames(scores$scores), xlab=Age,ylab=Mean item score) I need to change the plotting character and line type of the graph according to the scores (Agree,Conscientious,Extraticism,Openness). I have tried with: error.bars.by(scores$scores,round(bfi$age/10)*10,by.var=TRUE, main=BFI age trends,legend=3,labels=colnames(scores$scores), pch=c(1,2,3,4), lty=1 ,xlab=Age,ylab=Mean item score) But there is a problem: Error in localWindow(xlim, ylim, log, asp, ...) : formal argument pch matched by multiple actual arguments Anyone can help me for this problem. Hi Tham, When I run your example, I get the following error: Error in seq.default(clim, -clim, 0.01) : 'from' cannot be NA, NaN or infinite In addition: Warning messages: 1: In qt(1 - alpha/2, group.stats[[g]]$n - 1) : NaNs produced 2: In dt(ln, n - 1) : NaNs produced 3: In qt(alpha/2, n - 1) : NaNs produced As I don't know what is happening here, I can't do anything about the pch problem. Jim __ 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. William Revelle http://personality-project.org/revelle.html Professorhttp://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 __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Identifying one or more TRUE in the middle of an array
Yet another way which returns the row and column of the items you want rc - which(t(x[,-c(1,ncol(x))]),arr.ind=TRUE) #this identifies the rows and columns but is one column off rc[,1] - rc[,1] +1 #this adjusts the columns colnames(rc) - c(col,row) rc #show them Bill On Jun 6, 2014, at 5:27 PM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: Here is my solution. falses - which(!x) first.false - head(falses, 1) last.false - tail(falses, 1) which(x[first.false:last.false]) + first.false - 1 Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey Van: r-help-boun...@r-project.org [r-help-boun...@r-project.org] namens Fisher Dennis [fis...@plessthan.com] Verzonden: vrijdag 6 juni 2014 23:45 Aan: r-h...@stat.math.ethz.ch Onderwerp: [R] Identifying one or more TRUE in the middle of an array R 3.1.0 OS X Colleagues I have an array (I am using T/F rather than TRUE/FALSE for convenience) that could have patterns like: c(T, T, T, F, F, F, T, F, T, T, T) ## T at either end, a single T in the middle c(F, F, F, F, F, T, F, F, T, T, T) ## T at the tail end, a single T in the middle c(T, T, T, F, F, T, T, F, F, F, F) ## T at the front end, two T in the middle c(T, T, T, F, F, T, T, F, T, F, F) ## T at the front end, three T in the middle (not contiguous) c(F, F, F, F, F, T, F, F, F, F, F) ## no T at either end, a single T in the middle There might (or might not) be one or more T at the beginning (or the end). There might or might not be one or more T in the middle (not in a series that continues to either end) and the position of these T values varies. I am trying to identify the indices (if any) of these T values in the middle A brute force approach would be to strip off any contiguous T values from each end, then look for any remaining T values. Can anyone propose a more clever approach? Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com [[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. * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] plot in package psych with function error.bars.by
Tham and Jim, As usual, my first response to this is when you find a problem with the psych package, write me (as author) as well as the R-help list. In addition, always include which version of psych you are running. That will help in the debugging. The current version 1.4.5 on CRAN draws “cats eyes” instead of error bars, unless you turn off that option. You might find that useful. Then, my comment to Tham, Yes, you have found a weakness (some would say a bug) in that I currently default the base plot character to be 15. I will correct this in the next release (which won’t be shipped to CRAN until mid to late July). In the interim, I will try to get a fix up on the personality-project.org/r repository by early next week. To Jim, I can not get your error at all. Tham was finding a problem with the basic example, which works, unless you try to specify the pch, which doesn’t work. Bill On Jun 3, 2014, at 4:10 PM, Jim Lemon j...@bitwrit.com.au wrote: On Mon, 2 Jun 2014 11:28:19 PM Tham Tran wrote: Hi, I have a problem with the function error.bars.by in package psych. This is the code for example of a graph: keys.list=list(Agree=c(-1,2:5),Conscientious=c(6:8,-9,-10),Extraversion=c(-1 1,-12,13:15),Neuroticism=c(16:20),Openness = c(21,-22,23,24,-25)) keys = make.keys(28,keys.list,item.labels=colnames(bfi)) scores = score.items(keys,bfi,min=1,max=6) require(psych) error.bars.by(scores$scores,round(bfi$age/10)*10,by.var=TRUE, main=BFI age trends,legend=3,labels=colnames(scores$scores), xlab=Age,ylab=Mean item score) I need to change the plotting character and line type of the graph according to the scores (Agree,Conscientious,Extraticism,Openness). I have tried with: error.bars.by(scores$scores,round(bfi$age/10)*10,by.var=TRUE, main=BFI age trends,legend=3,labels=colnames(scores$scores), pch=c(1,2,3,4), lty=1 ,xlab=Age,ylab=Mean item score) But there is a problem: Error in localWindow(xlim, ylim, log, asp, ...) : formal argument pch matched by multiple actual arguments Anyone can help me for this problem. Hi Tham, When I run your example, I get the following error: Error in seq.default(clim, -clim, 0.01) : 'from' cannot be NA, NaN or infinite In addition: Warning messages: 1: In qt(1 - alpha/2, group.stats[[g]]$n - 1) : NaNs produced 2: In dt(ln, n - 1) : NaNs produced 3: In qt(alpha/2, n - 1) : NaNs produced As I don't know what is happening here, I can't do anything about the pch problem. Jim __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Help with polychoric correlation in psych library
Simon, As is usually the case with problems with a package, if you write the author/maintainer, you are more likely to get an answer. In this case, I just happened to be readiing R-help (t is the end of the term and I am relaxing). I am happy to look at this if you would send me the data set. What version of the psych package are you using? Bill On Jun 2, 2014, at 3:49 PM, Simon Kiss sjk...@gmail.com wrote: Hello I have a data.frame of 32 variables, all are ordered factors. str(dat) returns the following 'data.frame': 32 obs. of 43 variables: $ q1a: Ord.factor w/ 6 levels Strongly Disagree..: 3 4 2 5 NA NA 5 5 3 5 ... $ q1b: Ord.factor w/ 6 levels Strongly Disagree..: 3 NA 4 NA NA NA NA 5 4 4 ... $ q1c: Ord.factor w/ 6 levels Strongly Disagree..: NA NA 5 5 NA 4 NA 5 NA 5 ... $ q1d: Ord.factor w/ 6 levels Strongly Disagree..: 5 NA 5 NA NA 5 NA 5 NA 4 ... $ q1e: Ord.factor w/ 6 levels Strongly Disagree..: 5 NA NA 5 5 NA NA 5 5 NA ... $ q1f: Ord.factor w/ 6 levels Strongly Disagree..: 4 5 5 5 5 5 5 4 5 5 ... I'm trying to come up with a polychoric correlation matrix for these, and so I convert them to numeric values: 'data.frame': 32 obs. of 43 variables: $ q1a: num 3 4 2 5 NA NA 5 5 3 5 ... $ q1b: num 3 NA 4 NA NA NA NA 5 4 4 ... $ q1c: num NA NA 5 5 NA 4 NA 5 NA 5 ... $ q1d: num 5 NA 5 NA NA 5 NA 5 NA 4 ... and try: library(psych) polychoric(values, na.rm=TRUE), but this returns the following error The items do not have an equal number of response alternatives, global set to FALSE Error in poly[1, ] : incorrect number of dimensions In addition: Warning message: In mclapply(seq_len(n), do_one, mc.preschedule = mc.preschedule, : all scheduled cores encountered errors in user code Can anyone provide any guidance? Thanks, Simon Kiss * Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada N3T 2C9 Cell: +1 905 746 7606 __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Issues with fa() function in psych
Sagnik, I did some more checking and in fact you can do equamax through GPA rotation. (Gunter Nickel pointed this out in a post to R-help). I will implement this in version 1.4.6 (1.4.5 is now working its way through the various CRAN mirrors). You might like 1.4.5 in that I have added various ways of displaying confidence intervals (cats eye plots) as well as upper and lower confidence limits for correlations (cor.plot.upperLowerCi) Bill On Apr 10, 2014, at 1:22 AM, sagnik chakravarty sagnik.st...@gmail.com wrote: Thanks a lot Bill and Revelle for your helpful response. It would have been great if I could know when we can expect the release of the edited version 1.4.4. Sagnik On Wed, Apr 9, 2014 at 8:05 PM, William Revelle li...@revelle.net wrote: Sagnik raises the question as to why the psych package does not offer the ‘equamax’ rotation. It is because all rotations are handled through the GPArotation package which does not offer equamax. Sagnik also points out that if the requested rotation is not available, fa defaults to rotate=“none” without any warning. I have fixed that for the next release (1.4.4). (1.4.4 also will fix a bug in corr.test introduced into 1.4.3). The question about why printing just the loadings matrix leaves blank cells? That is because the loadings matrix of class “loadings” which the default print function prints with a cut = .3. Using the example from Sagnik, print(efa_pa$loadings,cut=0) will match the output of efa_pa. The fm=“pa” option runs conventional principal axis factor analysis (ala SPSS). As documented, this iterates max.iter times Not all factor programs that do principal axes do iterative solutions. The example from the SAS manual (Chapter 26) is such a case. To achieve that solution, it is necessary to specify that the max.iterations = 1. Comparing that solution to an iterated one (the default) shows that iterations improve the solution. In addition, fm=minres or fm=mle produces even better solutions for this example.” The com column is factor complexity using the index developed by Hofmann (1978). It is a row wise measure of item complexity. I have added more documentation to this in 1.4.4 Bill On Apr 8, 2014, at 2:28 AM, Pascal Oettli kri...@ymail.com wrote: Hello, And what about submitting your suggestions directly to the package author/maintainer? And please don't post in HTML. Regards, Pascal On Tue, Apr 8, 2014 at 3:13 PM, sagnik chakravarty sagnik.st...@gmail.com wrote: Hi Team, I was using your psych package for factor analysis and was also comparing the results with SAS results. I have some suggestions and/or confusions regarding the fa() function in the package: - The fa() function *doesn't account for Heywood cases* (communality greater than 1) and never ever throws out any error related to that which other softwares do. This is a serious and common issue in iterative factor analysis and hence should have been accounted for. - The fa() function doesn't provide equamax rotation in its rotation list and still if you specify *rotation=equamax*, it will run without throwing out any error and even mentioning in the result that equamax has been applied. But I have thoroughly compared results from *rotation=none* and *rotation=equamax* options and they are exactly same. *That means fa() is not doing the rotation at all and yet telling that it is doing that!!* I have even mentioned *rotation=crap* option just to check and surprisingly it ran(without any error) with the result showing: *Factor Analysis using method = gls* * Call: fa(r = cor_mat, nfactors = 4, n.obs = 69576, rotate = crap, fm = gls)* I hope you understand the severity of this bug and hence request you to correct this. - To my sense, there might be some problem with fm=ml and fm=pa options since the convergence issue should be with MLE method and not PA method but while running factor analysis with PA, I am getting the following warning: *maximum iteration exceeded* *The estimated weights for the factor scores are probably incorrect. Try a different factor extraction method.* If I compare the results of R and SAS,* I am getting convergence error for MLE in SAS whereas I am getting the same error for PA in R *!! I am not being able to understand this mismatch. - If I call the *loading matrix like efa_pa$loadings, the matrix shown has many blank cells whereas the final result showing the loadings doesn't have so* !! *Loadings:* * PA1PA2PA3PA4 * *Var10.401 -0.243* *Var20.336 -0.1040.710* *Var30.624 0.123 0.170 * - Could you please explain* what the com column means* in the output
Re: [R] Issues with fa() function in psych
I am probably going to push it to CRAN today or tomorrow. Bill On Apr 10, 2014, at 1:22 AM, sagnik chakravarty sagnik.st...@gmail.com wrote: Thanks a lot Bill and Revelle for your helpful response. It would have been great if I could know when we can expect the release of the edited version 1.4.4. Sagnik On Wed, Apr 9, 2014 at 8:05 PM, William Revelle li...@revelle.net wrote: Sagnik raises the question as to why the psych package does not offer the ‘equamax’ rotation. It is because all rotations are handled through the GPArotation package which does not offer equamax. Sagnik also points out that if the requested rotation is not available, fa defaults to rotate=“none” without any warning. I have fixed that for the next release (1.4.4). (1.4.4 also will fix a bug in corr.test introduced into 1.4.3). The question about why printing just the loadings matrix leaves blank cells? That is because the loadings matrix of class “loadings” which the default print function prints with a cut = .3. Using the example from Sagnik, print(efa_pa$loadings,cut=0) will match the output of efa_pa. The fm=“pa” option runs conventional principal axis factor analysis (ala SPSS). As documented, this iterates max.iter times Not all factor programs that do principal axes do iterative solutions. The example from the SAS manual (Chapter 26) is such a case. To achieve that solution, it is necessary to specify that the max.iterations = 1. Comparing that solution to an iterated one (the default) shows that iterations improve the solution. In addition, fm=minres or fm=mle produces even better solutions for this example.” The com column is factor complexity using the index developed by Hofmann (1978). It is a row wise measure of item complexity. I have added more documentation to this in 1.4.4 Bill On Apr 8, 2014, at 2:28 AM, Pascal Oettli kri...@ymail.com wrote: Hello, And what about submitting your suggestions directly to the package author/maintainer? And please don't post in HTML. Regards, Pascal On Tue, Apr 8, 2014 at 3:13 PM, sagnik chakravarty sagnik.st...@gmail.com wrote: Hi Team, I was using your psych package for factor analysis and was also comparing the results with SAS results. I have some suggestions and/or confusions regarding the fa() function in the package: - The fa() function *doesn't account for Heywood cases* (communality greater than 1) and never ever throws out any error related to that which other softwares do. This is a serious and common issue in iterative factor analysis and hence should have been accounted for. - The fa() function doesn't provide equamax rotation in its rotation list and still if you specify *rotation=equamax*, it will run without throwing out any error and even mentioning in the result that equamax has been applied. But I have thoroughly compared results from *rotation=none* and *rotation=equamax* options and they are exactly same. *That means fa() is not doing the rotation at all and yet telling that it is doing that!!* I have even mentioned *rotation=crap* option just to check and surprisingly it ran(without any error) with the result showing: *Factor Analysis using method = gls* * Call: fa(r = cor_mat, nfactors = 4, n.obs = 69576, rotate = crap, fm = gls)* I hope you understand the severity of this bug and hence request you to correct this. - To my sense, there might be some problem with fm=ml and fm=pa options since the convergence issue should be with MLE method and not PA method but while running factor analysis with PA, I am getting the following warning: *maximum iteration exceeded* *The estimated weights for the factor scores are probably incorrect. Try a different factor extraction method.* If I compare the results of R and SAS,* I am getting convergence error for MLE in SAS whereas I am getting the same error for PA in R *!! I am not being able to understand this mismatch. - If I call the *loading matrix like efa_pa$loadings, the matrix shown has many blank cells whereas the final result showing the loadings doesn't have so* !! *Loadings:* * PA1PA2PA3PA4 * *Var10.401 -0.243* *Var20.336 -0.1040.710* *Var30.624 0.123 0.170 * - Could you please explain* what the com column means* in the output:? * PA1 PA3 PA2 PA4 h2 u2 com* *Var1 0.44 0.14 -0.03 -0.10 0.22665 0.773 1.3* *Var2 0.08 0.11 0.02 0.78 0.62951 0.370 1.1* *Var3 0.62 0.12 0.15 0.14 0.43578 0.564 1.3* - Request you to add option for *equamax rotation* also if possible. I have come across the above issues until now. Please do correct me if I am
Re: [R] Issues with fa() function in psych
and provide commented, minimal, self-contained, reproducible code. -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] How to replace NA values
Bruce, use the is.na function, e.g., Bats.cast[is.na(Bats.cast)] - 0 Bill On Jul 28, 2013, at 8:12 AM, Bruce Miller batsnc...@gmail.com wrote: Hi all, I am using reshape2 to reformat a data frame and all is great using: Bats.melt - melt(data = Bats) Bats.cast - dcast(data = Bats.melt, formula = Species ~ Location) dput(Bats.cast,'C:/=Bat data working/Nica_new/Bats_niche.robj') write.csv(Bat.cast,'C:/=Bat data working/Nica_new/test_Niche.csv') The resulting file from both dput and write are great, however in order to run another R analysis I need to replace all the NA values in the output with a zero - 0 value. I have just been opening this in Excel and using a simple find NA replace with 0 and saving then reopening in R. There must be a simple way to do this in R. Any suggestions welcomed. [[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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] compute Mcdonald's omega ω
Dear codecat, To track down where the trouble is, try lapply(my.data,is.numeric) That will tell you which column of your data is giving you problems. It is possible that you read the data in from SPSS and did not turn off the use.value.labels switch. On Jun 11, 2012, at 1:55 AM, codec cat wrote: Hi I keep having this error when I used omega(my.data) Error in cor(m, use = pairwise) : 'x' must be numeric I'm quite sure my data is numeric as I have tried several methods such as opening csv in notepad and make sure the number is not string, also tried SPSS and make sure the numbers are set to numeric.. can somebody advice me what is wrong. Thanks. On 11 June 2012 04:17, William Revelle li...@revelle.net wrote: Dear codecat You can get the most recent version of psych from CRAN. The current version is 1.2.4. Then, the help page for omega should be of use library(psych) ?omega In addition, try the vignette for the psych package. Or, as of today, there is a more detailed instruction for newbies on using the psych package and R to find omega http://personality-project.org/r/tutorials/R_for_omega.pdf Let me know if any of this helps. Bill On Jun 10, 2012, at 4:00 PM, codec cat wrote: Dear all I am a newbie to R and I would appreciate it very much if someone can give me some advice on this. Please note that I am not a programmer so some of the questions might sound really stupid. I would like to compute McDonald's omega calculation using R, I'm aware I can use the omega function in the psych package. But I'm really not sure how to do it. I have read these two articles that explain about omega- http://personality-project.org/r/html/omega.html and http://personality-project.org/r/r.omega.html But I'm still not sure how to do it. Can someone correct me what I have gone wrong. I'm following the instruction from this site and I have downloaded the psych package- http://personality-project.org/r/ *1. Load and read the data* datafilename - file.choose() # use the OS to find the file person.data - read.table(datafilename,header=TRUE) #read the data file *2. Use the code examples from http://personality-project.org/r/r.omega.html* Copy and paste the whole code from this website in the R console I know I must have understood Step 2 incorrectly, but I am really not sure what to do with the omega function. Can someone give me more specific help on this please. 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] compute Mcdonald's omega ω
Dear codecat You can get the most recent version of psych from CRAN. The current version is 1.2.4. Then, the help page for omega should be of use library(psych) ?omega In addition, try the vignette for the psych package. Or, as of today, there is a more detailed instruction for newbies on using the psych package and R to find omega http://personality-project.org/r/tutorials/R_for_omega.pdf Let me know if any of this helps. Bill On Jun 10, 2012, at 4:00 PM, codec cat wrote: Dear all I am a newbie to R and I would appreciate it very much if someone can give me some advice on this. Please note that I am not a programmer so some of the questions might sound really stupid. I would like to compute McDonald's omega calculation using R, I'm aware I can use the omega function in the psych package. But I'm really not sure how to do it. I have read these two articles that explain about omega- http://personality-project.org/r/html/omega.html and http://personality-project.org/r/r.omega.html But I'm still not sure how to do it. Can someone correct me what I have gone wrong. I'm following the instruction from this site and I have downloaded the psych package- http://personality-project.org/r/ *1. Load and read the data* datafilename - file.choose() # use the OS to find the file person.data - read.table(datafilename,header=TRUE) #read the data file *2. Use the code examples from http://personality-project.org/r/r.omega.html* Copy and paste the whole code from this website in the R console I know I must have understood Step 2 incorrectly, but I am really not sure what to do with the omega function. Can someone give me more specific help on this please. 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] inter-item-correlation-table
David, See corr.test in the psych package. Bill On May 18, 2012, at 9:35 AM, David Studer wrote: Hi everybody! Does anyone know how to obtain a inter-item-correlation-table (with p-values or significance-levels)? (as SPSS does, either spearman or pearson) Repeatedly using cor.test() is pretty exhausting as the table size increases... Thank you! David [[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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] computing scores from a factor analysis
Wolfgang, Since you seem to be doing this in the psych package, it would have been faster to directly ask the author (me). Luckily, I saw the question on R-Help. The principal components step is being done on the correlation matrix, not on the raw data matrix, thus, it is not able to find scores. However, since you have the components solution, you also the scoring weights. Taking your analysis: tetra - tetrachoric (image_na, correct=TRUE) t_matrix - tetra$rho pca.tetra - principal(t_matrix, nfactors = 10, n.obs = nrow(image_na), rotate=varimax, scores=FALSE) scores - image_na %*% pca.tetra$weights Bill On Jan 18, 2012, at 4:27 AM, wolfgang wrote: Haj i try to perform a principal component analysis by using a tetrachoric correlation matrix as data input tetra - tetrachoric (image_na, correct=TRUE) t_matrix - tetra$rho pca.tetra - principal(t_matrix, nfactors = 10, n.obs = nrow(image_na), rotate=varimax, scores=TRUE) the problem i have is to compute the individual factor scores from the pca. the code runs perfect if i do not ask for the scores if i ask for the scores i get an error message Error in scale(x.matrix): object 'x.matrix' not found can somebody help me? cheers wolfgang -- View this message in context: http://r.789695.n4.nabble.com/computing-scores-from-a-factor-analysis-tp4306234p4306234.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 5 minutes to midnighthttp://www.thebulletin.org __ 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] Base function for flipping matrices
Hadley, Presumably for fliplr you meant ncol(x) fliplr - function(x) x[, ncol(x):1] Bill On Dec 31, 2011, at 9:08 AM, Hadley Wickham wrote: Hi all, Are there base functions that do the equivalent of this? fliptb - function(x) x[nrow(x):1, ] fliplr - function(x) x[, nrow(x):1] Obviously not hard to implement (although it needs some more checks), just wondering if it had already been implemented. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] Help with PCA
Sarah and elisacarli21 principal in the psych package will do principal components of a correlation or covariance matrix. ex: library(psych) principal(Thurstone,3,rotate=none) #First three principal components of the Thurstone correlation matrix #compare with eigen e - eigen(Thurstone) #perform an eigen value decomposition e #show the resuls e$vectors %*% diag(sqrt(e$values)) #convert to loadings and compare with the output from principal Bill On Dec 28, 2011, at 9:09 AM, Sarah Goslee wrote: Hi, On Wed, Dec 28, 2011 at 7:54 AM, elisacarli21 elisacarl...@gmail.com wrote: Dear all, I've a correlation matrix with rows and columns headings. I've two questions: 1) How can i import it in R, setting first row as row heading and first column as column heading? read.table, with the appropriate options. You can see what they are by typing ?read.table at an R prompt. 2) Which is the best principal component anlysis package in R? Best for what? I'd start with ?princomp and if that doesn't meet your needs go looking farther. www.rseek.org is good for finding R functions for particular purposes. But if you're starting with the correlation matrix rather than the raw data, you might need to do the eigenanalysis yourself rather than relying on an existing function that assumes raw data. Sarah -- Sarah Goslee http://www.functionaldiversity.org __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] Help creating a symmetric matrix?
Dear Matt, Sarah and Rui, To answer the original question for creating a symmetric matrix v-c(0.33740, 0.26657, 0.23388, 0.23122, 0.21476, 0.20829, 0.20486, 0.19439, 0.19237, 0.18633, 0.17298, 0.17174, 0.16822, 0.16480, 0.15027) z-diag(6) z[row(z) col(z)] - v z - z + t(z) diag(z) - 0 z [,1][,2][,3][,4][,5][,6] [1,] 0.0 0.33740 0.26657 0.23388 0.23122 0.21476 [2,] 0.33740 0.0 0.20829 0.20486 0.19439 0.19237 [3,] 0.26657 0.20829 0.0 0.18633 0.17298 0.17174 [4,] 0.23388 0.20486 0.18633 0.0 0.16822 0.16480 [5,] 0.23122 0.19439 0.17298 0.16822 0.0 0.15027 [6,] 0.21476 0.19237 0.17174 0.16480 0.15027 0.0 Bill On Dec 24, 2011, at 6:04 AM, Sarah Goslee wrote: Or the slightly shorter: z-diag(6) z[row(z) col(z)] - v which is what lower.tri() does, and z - diag(6) z[lower.tri(z)] - v also works. Sarah On Fri, Dec 23, 2011 at 9:31 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Matt Considine wrote Hi, I am trying to work with the output of the MINE analysis routine found at http://www.exploredata.net Specifically, I am trying to read the results into a matrix (ideally an n x n x 6 matrix, but I'll settle right now for getting one column into a matrix.) The problem I have is not knowing how to take what amounts to being one half of a symmetric matrix - excluding the diagonal - and getting it into a matrix. I have tried using lower.tri as found here https://stat.ethz.ch/pipermail/r-help/2008-September/174516.html but it appears to only partially fill in the matrix. My code and an example of the output is below. Can anyone point me to an example that shows how to create a matrix with this sort of input? Thank you in advance, Matt #v-newx[,3] #or, for the sake of this example v-c(0.33740, 0.26657, 0.23388, 0.23122, 0.21476, 0.20829, 0.20486, 0.19439, 0.19237, 0.18633, 0.17298, 0.17174, 0.16822, 0.16480, 0.15027) z-diag(6) ind - lower.tri(z) z[ind] - t(v)[ind] z [,1][,2] [,3] [,4] [,5] [,6] [1,] 1.0 0.00000 [2,] 0.26657 1.00000 [3,] 0.23388 0.192371000 [4,] 0.23122 0.18633 NA100 [5,] 0.21476 0.17298 NA NA10 [6,] 0.20829 0.17174 NA NA NA1 Hello, Aren't you complicating? In the last line of your code, why use 'v[ind]' if 'ind' indexes the matrix, not the vector? z-diag(6) ind - lower.tri(z) z[ind] - v#This works z Rui Barradas -- Sarah Goslee http://www.functionaldiversity.org __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] Correlation Matrix in R
Alexandre, The output from corr.test is a list of matrices. To export one of those matrices, simply specify which one you want: Using the example from my previous note: library(psych) examp - corr.test(sat.act) mat.c.p - lower.tri(examp$r)*examp$r + t(lower.tri(examp$p)*examp$p) mat.c.p mat.cp is a matrix and can be directly written using write.table (if you want). To find out what are the elements of the list produced by corr.test, use the str command; str(examp) will produce List of 5 $ r : num [1:6, 1:6] 1 0.0873 -0.0209 -0.0365 -0.0188 ... ..- attr(*, dimnames)=List of 2 .. ..$ : chr [1:6] gender education age ACT ... .. ..$ : chr [1:6] gender education age ACT ... $ n : num [1:6, 1:6] 700 700 700 700 700 687 700 700 700 700 ... ..- attr(*, dimnames)=List of 2 .. ..$ : chr [1:6] gender education age ACT ... .. ..$ : chr [1:6] gender education age ACT ... $ t : num [1:6, 1:6] Inf 2.314 -0.551 -0.965 -0.498 ... ..- attr(*, dimnames)=List of 2 .. ..$ : chr [1:6] gender education age ACT ... .. ..$ : chr [1:6] gender education age ACT ... $ p : num [1:6, 1:6] 0 0.0209 0.5818 0.3349 0.6187 ... ..- attr(*, dimnames)=List of 2 .. ..$ : chr [1:6] gender education age ACT ... .. ..$ : chr [1:6] gender education age ACT ... $ Call: language corr.test(x = sat.act) - attr(*, class)= chr [1:2] psych corr.test To export one of those as a text file you could just copy the output, or you can write.table one element. e.g., write.table(examp$r) Bill On Nov 1, 2011, at 4:43 AM, AlexC wrote: Hello, Thank you for your replies. I cannot run the function rcor.test even when having loaded package ltm. Perhaps it has to do with the fact that I am using the latest version of R and this package wasn't created under that version The function corr.test in package psych works fine. Is there anyway to export the results in a txt or csv file? Since it isn't in a data frame format it cannot simply be exported using write.table Alexandre -- View this message in context: http://r.789695.n4.nabble.com/Correlation-Matrix-in-R-tp3938274p3962939.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] Correlation Matrix in R
Alex, corr.test in psych will give you a matrix of correlations, a matrix of sample sizes, and a matrix of probabilities. You can combine the correlations and the probabilities to form what you want: try the following: library(psych) examp - corr.test(sat.act) mat.c.p - lower.tri(examp$r)*examp$r + t(lower.tri(examp$p)*examp$p) mat.cp Bill On Oct 26, 2011, at 6:03 AM, AlexC wrote: Thank you for your quick reply and helpful advice. Using this argument allows me to do what I needed to do Now the only other thing I wanted to accomplish was to obtain the top half of the matrix with p values and the bottom half with the correlations, to observe the significant correlations. I have been able to use a few functions such as rcorr, and cor.matrix to get such information but it isn't output in a format that I can save with the write.table function or write.clipboard the pair function allows a graphical display of the data on the other hand (with correlation graphics on the bottom half) and I have added an argument which allows to view the significant p values. But I wanted to know if I could also do the above easily. -- View this message in context: http://r.789695.n4.nabble.com/Correlation-Matrix-in-R-tp3938274p3940170.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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] Labels in ICLUST
On Oct 11, 2011, at 2:28 AM, Steve Powell wrote: Dear all, I can't get the labels slot in ICLUST to accept a character vector. library(psych) test.data - Harman74.cor$cov ic.out - ICLUST(test.data,nclusters =4,labels=letters[1:ncol(test.data)]) ## Error in !labels : invalid argument type ic.out - ICLUST(test.data,nclusters =4,labels=1:ncol(test.data)) ## OK Any ideas? __ 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. Steve, That is a bug in ICLUST. It is now fixed (as of reading your email) and the updated version should be released this weekend. In the meantime, a workaround, is to label the columns with the labels you want. colnames(test.data ) - letters[1:ncol(test.data)] ic.out - ICLUST(test.data,4) Bill William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] how do i put two scatterplots on same graph
If the data are from one data.frame (e.g., the iris data set), then simply label the red and white flowers with different colors: e.g., with the iris data set plot(iris$Sepal.Length,iris$Sepal.Width,col=c(red,blue,black)[iris$Species],pch=c(16:18)[iris$Species]) Bill On Oct 4, 2011, at 4:20 AM, Paul Hiemstra wrote: On 10/04/2011 06:19 AM, jricci wrote: Have two sets of scatterplot data hypothetically a) stem lenght vs number of petals in red flowers b) stem lenght vs number of petals in white flowers want to place on same scatter plot with same x,y axis but different collored markers How do I do this in R -- View this message in context: http://r.789695.n4.nabble.com/how-do-i-put-two-scatterplots-on-same-graph-tp3870030p3870030.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. Hi, You could take a look at the ggplot2 package. good luck, Paul -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ 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. William Revellehttp://personality-project.org/revelle.html Professor http://personality-project.org Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern Universityhttp://www.northwestern.edu/ Use R for psychology http://personality-project.org/r It is 6 minutes to midnighthttp://www.thebulletin.org __ 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] Boxplot BUT with Mean, SD, Max Min ?
Dear Phil, An alternative solution is to draw a regular Tukey Box Plot but overlay the means +/- 1 sd: boxplot(anscombe) psych:::error.bars(anscombe,sd=TRUE,add=TRUE) Bill At 3:45 AM +1000 9/27/11, Philip Rhoades wrote: Gabor, Bill, On 2011-09-27 02:51, Gabor Grothendieck wrote: On Mon, Sep 26, 2011 at 12:11 PM, Philip Rhoades p...@pricom.com.au wrote: Gabor, On 2011-09-27 00:35, Gabor Grothendieck wrote: On Mon, Sep 26, 2011 at 9:56 AM, Philip Rhoades p...@pricom.com.au wrote: People, It appears that there is no way of getting Boxplots to plot using Mean, SD, Max Min - is there something else that would do what I want? I couldn't find it . . Try replacing the stats component of boxplot's output with your desired statistics and then feeding that into the lower level bxp function to do the graphics: bp - boxplot(Nile, plot = FALSE) bp$stats - matrix(c(min(Nile), mean(Nile) + c(-1, 0, 1) * sd(Nile), max(Nile))) bxp(bp) Thanks for that! What is the syntax when there is more than one set of data (ie a two dimensional vector)? I tried messing around with stuff like: mean(Nile[,2] etc but I get subscript out of range errors . . Bill's example shows how to do it with a list of numeric vectors. Here is another example using the built in anscombe and making use of my prior code, Bill's and Vining's: bp - boxplot(anscombe, plot = FALSE) bp$stats - sapply(anscombe, function(x) c(min(x), mean(x) + c(-1, 0, 1) * sd(x), max(x))) bxp(bp, outline = FALSE) Interesting! - I've learnt something about anscombe and sapply and other stuff (thanks again!) but I think I mis-spoke before. I think what I want is a list of numeric vectors but when I created tarr: tarr - array( dim = c( 5,3 ), c( 1,2,3,4,5,2,3,4,5,6,3,4,5,6,7 ) ) I couldn't get it to work with the original code . . now I have had a closer look at Bill's code . . On the original question though, why isn't there something off the shelf that will do what I want? Surely, a boxplot using mean, SD, max and min would be a common enough need to justify it? Thanks, Phil. -- Philip Rhoades GPO Box 3411 Sydney NSW 2001 Australia E-mail: p...@pricom.com.au __ 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] Q and R mode in Principal Component Analysis
At 4:10 PM +0100 9/6/11, Lívio Cipriano wrote: Hi, Can anyone explain me the differences in Q and R mode in Principal Component Analysis, as performed by prcomp and princom respectively. Dear Livio, The help file of prcomp says it pretty well: The calculation is done by a singular value decomposition of the (centered and possibly scaled) data matrix, not by using eigen on the covariance matrix. This is generally the preferred method for numerical accuracy. with the help file from princomp: princomp only handles so-called R-mode PCA, that is feature extraction of variables. If a data matrix is supplied (possibly via a formula) it is required that there are at least as many units as variables. For Q-mode PCA use prcomp. This R and Q (as well as S and T) terminology was introduced (at least in psychology) by Ray Cattell in his discussion of the Data Box. It is the idea that you can consider three dimensions of data (across subjects, variables, and time). Then there are six different ways to cut up the data. A typical data matrix has rows for observations and columns for variables. Typically the number of rows columns. If you are trying to find a structure that reduces the complexity of the variables, you do the normal analysis (R) of the variables. An alternative is do the analysis on the transpose of the data matrix (Q analysis). That is, to try to reduce the complexity of the rows. This is not a problem if you do aingular value decomposition (which is what prcomp does). It can be if you do a princomp analysis which is based upon the covariance of the data. Let nXv represent your original matrix. (n observations on v variables). For an R analysis, using princomp, you are finding the principal components of the covariance matrix C which is of size v x v with rank = the lesser of n and v. But for a Q analysis, if you are using princomp, you are still trying to find the principal components of a covariance matrix C* which has dimensions n x n but has a rank of the lesser of n and v. That is, if the number of rows number of columns the rank of the covariance matrix of the transposed matrix will still be the number of columns although the size of the correlation matrix will be n x n. Q analysis is looking for patterns of similarity in the subjects over variables, R analysis is looking for similarity in the variables over subjects. This then gets generalized to the case of subjects over time, variables, over time, The data box emphasized that we are not limited to correlating tests over people at one time. In its 1946 formulation, there were six 'designs of covariation using literal measurement' and 12 'designs of covariation using differential or ratio measurement' (Cattell, 1946c, p 94-95). Considering Persons, Tests, and Occasions as the fundamental dimensions, it was possible to generalize the normal correlation of Tests over Persons design (R analysis) to consider how Persons correlated over Tests (Q analysis), or Tests over Occasions (P analysis), etc. Cattell (1966) extended the data box's original three dimensions to five by adding Background or preceding conditions as well as Observers (see also Cattell (1977)). Applications of the data box concept have been seen throughout psychology, but the primary influence has probably been on those who study personality development and change over the life span (McArdle Bell, 2000, Mroczek, 2007, Nesselroade, 1984). Unfortunately, even for the original three dimensions, Cattell (1978) used a different notation than he did in Cattell (1966, 1977) or Cattell (1946b). British Journal of Psychology (2009), 100, 253-257 q 2009 The British Psychological Society [1] R. B. Cattell. The data box: Its ordering of total resources in terms of possible relational systems. In R. B. Cattell, editor, Handbook of multivariate experimental psychology, pages 67-128. Rand-McNally, Chicago, 1966. I suspect this is more than you wanted to know. Bill Regards Lívio Cipriano __ 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] How to get the descriptive statistic of the whole dataframe?
At 10:31 AM +0200 8/18/11, Petr PIKAL wrote: Hi look into the *apply series of functions. In your case apply(name.of.your.data.frame,2,min) or apply(name.of.your.data.frame,2,max) will do. You can also put any summary function to your liking instead of min/max. And summary has its own data frame method so simply summary(name.of.your.data.frame) There is also fivenum function and more elaborated describe in Hmisc I believe :-) There are at least 3 different describe functions, all useful, but with somewhat different output describe (psych) describe (Hmisc) describe (prettyR) One of these will probably do just what you want. Bill Regards Petr Best, Daniel Lao Meng wrote: Hi all: If I have a dataframe of N columns.If I wanna get the min(or max,or mean...etc)of the whole dataframe,how to do it quickly? What I can do is only: min(data[,1:ncol(data)]) Any other suggestion? Thanks! best [[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. -- -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] very large pair() plot
In addition to Uwe's suggestion of creating a pdf and then plotting to it, it is useful to set the gap size to 0 (gap=0) You might also look at pairs.panels in the psych package which implements one of the examples in pairs (i.e., it gives histograms on the diagonal and reports the correlation above the diagonal). Bill At 11:30 AM -0600 6/30/11, Greg Snow wrote: In addition to Uwe's answer, you might also want to consider the pairs2 function in the TeachingDemos package. It lets you plot sections of the overall scatterplot matrix rather than the whole thing, so you could spread the entire scatterplot matrix over multiple pages. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of ahrager Sent: Wednesday, June 29, 2011 3:28 PM To: r-help@r-project.org Subject: [R] very large pair() plot Hi everyone, I'm a newbie and this is my first post. My boss wants me to make a series of scatter plots where 76 variables are plotted against each other. I know how to do this using pair()...my problem is that there are just too many plots to fit in the window. Is there any way I can get all the plots to fit and make the font size and marker size scale so it is readable? My goal is to create a *.pdf file that I can send to our large plotter. Thank you, Audrey Rager -- View this message in context: http://r.789695.n4.nabble.com/very-large- pair-plot-tp3634075p3634075.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-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] Factor analysis on ordinal nominal data
At 6:19 AM -0700 6/14/11, Jay wrote: Hi, are there readily available R packages that are able to perform FA on ordinal and/or nominal data? If not, what other approaches and helpful packages would you suggest? If by ordinal and nominal you mean just a few categories (e.g., a mood scale or personality item), then try irt.fa in the psych package or find the polychoric correlations and use any factor analysis function (e.g., fa in psych, factanal in core R). BR, Jay __ 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] Side by side scatter plots with specified regression lines
Dear Sigrid, At 12:46 PM -0700 6/12/11, Sigrid wrote: I am new and self taught in R, so please bear with me. I want to create two scatter plots side by side. The data set includes measurements from two different countries with 7 treatments over a timeline (x-axis). Problem 1 I want to have each plot to include the data from one of the countries with 7 regression lines of the treatments, but I do no know how to divide the data between them. This is how I created one plot with all the data. plot(YEAR,YIELD,col=red,xlab=Year,ylab=Yield,xlim=c(1,4),ylim=c(1,150)) Problem 2 The models I've found to describe the regression lines of the treatments seems to be different than the default ablines that R creates. I have the values of the exact values of intercepts and slopes, but does not know how to add them to the graph. This is what I got so far. abline(lm(YIELD[TREATMENT==A]~YEAR[TREATMENT==A]),lty=2,col=1) I hope this is enough to give me some pointers, otherwise I will try to elaborate. Thank you for your help. Here is an example that might help: library(psych) #in order to get the sat.act data set my.data - sat.act with(my.data,plot(SATV~SATQ, col=c(blue,red)[gender])) by(my.data,my.data$education, function(x) abline (lm(SATV~SATQ,data=x), lty=c(solid, dashed, dotted, dotdash, longdash, twodash)[(x$education+1)])) #to make two scatter plots side by side, use op - par(mfrow=c(1,2)) I hope this helps. Bill -- View this message in context: http://r.789695.n4.nabble.com/Side-by-side-scatter-plots-with-specified-regression-lines-tp3592473p3592473.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-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] how to not match partial names
Dear friends, How do I stop partial matching of list names? e.g., x - list(=a, B=b) is.null(x$A) #returns FALSE even though there is no element A. if(is.null(x$A)) {result - x$} else {result - x$A} result #is even though there is no x$A element x - list(=a, B=b) if(is.null(x$A)) {result - x$} else {result - x$A} result #this is great x - list(ABC=a, B=b) if(is.null(x$A)) {result - x$} else {result - x$A} result #partial matches and returns x - list(ABC=abc, B=b,AA=) if(is.null(x$A)) {result - x$} else {result - x$A} result #can not partial match, and thus returns x - list(AAB=aab, B=b,AA=) if(is.null(x$A)) {result - x$} else {result - x$A} result #also can not partial match My need for this is that I have several functions that return lists and I am trying to extract if it exists, but something else if it does not. Thanks. Bill -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] Bayesian PCA
Dear Lucy, You might consider some of the scale construction techniques available in the psych package. In particular, the iclust function is meant for this very problem: how to form reliable item composites. Bill At 4:38 PM +0100 4/12/11, Christian Hennig wrote: Dear Lucy, not an R-related response at all, but if it's questionnaire data, I'd probably try to do dimension reduction in a non-automated way by defining a number of 10 or so meaningful scores that summarise your questions. Dimension reduction is essentially about how to aggregate the given information into low-dimensional measurements, which according to my opinion should be rather driven by the research aim and meaning of the variables than by the distribution of the data, if at all possible. You can then use PCA in order to examine the remaining dimensions Christian On Tue, 12 Apr 2011, Lucy Asher wrote: First of all I should say this email is more of a general statistics questions rather than being specific to using R but I'm hoping that this may be of general interest. I have a dataset that I would really like to use PCA on and have been using the package pcaMethods to examine my data. The results using traditional PCA come out really nicely. The dataset is comprised of a set of questions on dog behaviour answered by their handlers. The questions fall into distinct components which may biological sense and the residuals are reasonable small. Now the problem. I don't have a big enough sample to run traditional PCA. I have about 40 dogs and 60 questions so which ever way you look at it not enough. There is past data available on some of the questions and the realtionships between them so I was wondering whether Bayesian PCA would be a useful alternative using past research to inform my priors. I wondered if anyone knew whether Bayesian PCA was better suited to smaller datasets than traditional (ML) PCA? If not I wondered if anyone knew of packages in R that could do dimension reduction on datasets with small sample sizes? Many Thanks, Lucy This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system: you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation. [[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. *** --- *** Christian Hennig University College London, Department of Statistical Science Gower St., London WC1E 6BT, phone +44 207 679 1698 chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche __ 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. -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] lavaan diagram
Sebastian, At 7:03 PM -0800 3/8/11, Peter Ehlers wrote: On 2011-03-08 18:09, Sebastián Daza wrote: Hi everyone, I got the following error when I tried to diagram a confirmatory factor analysis using lavaan: lavaan.diagram(conf) Error in strwidth(xvars) : plot.new has not been called yet Does anyone have any idea about what is happening? Thank you in advance. Two problems with this request: 1. It would be customary to mention that lavaan.diagram is in the psych package. 2. Is 'conf' of the appropriate class? Have you checked with str(conf)? As I said in a previous response to a lavaan.diagram question of yours, the currently released version of psych was released before lavaan 0.4-7 was released. In an improvement to the efficiency of the lavaan, Yves Rosseel changed some of the structure of the output . (See his very helpful introduction to lavaan at http://lavaan.ugent.be/.) lavaan.diagram is just a very short function in psych that calls structure.diagram (also in psych). Read the documentation for structure.diagram to see what it is looking for (basically two measurement models and a structure model) and then look at the lavann structure to see how to pass the appropriate parameters. Until I release the next version of psych the best solution is to look at the current version of lavaan.diagram (10 lines of code) and modify them to handle the structure of lavaan output. lavaan is a very nice product and lavaan.diagram is a minor attempt to make it even better. It would help me improve lavaan.diagram if you could send me a simple example of the data set you were examining and what was the model that did not diagram correctly. I hope that helps. Bill Peter Ehlers __ 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] Sweave with scan()-ed data
At 10:21 AM -0500 3/7/11, Michael Friendly wrote: In an Sweave slide, I want to use sem::read.moments() and sem::specify.model(), which work by using scan() to read the following lines, up to the first blank line. However, Sweave throws an error: Sweave(sem-thurstone.Rnw) Writing to file sem-thurstone.tex Processing code chunks ... 1 : term hide (label=arrests-setup) 2 : echo term hide (label=thurstone-data) Error: chunk 2 (label=thurstone-data) Error in sem-thurstone.Rnw:43:12: unexpected numeric constant 42: .828 43: .776 .779 ^ Is there some switch or option for Sweave that will make this work? Below is the slide in question in an executable example: \documentclass[dvipsnames,pdflatex,compress,beamer]{beamer} \usepackage{Sweave} \definecolor{Sinput}{rgb}{1,0,0} \definecolor{Scode}{rgb}{0,0,0.56} \definecolor{Soutput}{rgb}{0,0,1} \DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom={\color{Sinput}},fontsize=\footnotesize,baselinestretch=0.9} \DefineVerbatimEnvironment{Soutput}{Verbatim}{formatcom={\color{Soutput}},fontsize=\footnotesize,baselinestretch=0.85} \DefineVerbatimEnvironment{Scode}{Verbatim}{formatcom={\color{Scode}},fontsize=\small} \begin{document} \SweaveOpts{engine=R,height=6,width=6,results=hide,fig=FALSE,echo=TRUE} \SweaveOpts{prefix.string=fig/sem} \section{sem package: Second-order CFA, Thurstone data} \begin{frame}[fragile] \frametitle{sem package: Second-order CFA, Thurstone data} \framesubtitle{Data} Data on 9 ability variables: thurstone-data, echo=TRUE= R.thur - read.moments(diag=FALSE, names=c('Sentences','Vocabulary', 'Sent.Completion','First.Letters','4.Letter.Words','Suffixes', 'Letter.Series','Pedigrees', 'Letter.Group')) .828 .776 .779 .439 .493.46 .432 .464.425 .674 .447 .489.443 .59.541 .447 .432.401 .381.402 .288 .541 .537.534 .35.367 .32 .555 .38 .358.359 .424.446 .325 .598 .452 @ \end{frame} \end{document} At 10:31 AM -0500 3/7/11, Duncan Murdoch wrote: On 07/03/2011 10:21 AM, Michael Friendly wrote: In an Sweave slide, I want to use sem::read.moments() and sem::specify.model(), which work by using scan() to read the following lines, up to the first blank ...snip... 42: .828 43: .776 .779 ^ Is there some switch or option for Sweave that will make this work? I don't think so. The way Sweave works is not to pipe the code chunks into a console-like evaluator, it's to parse the whole code chunk, then evaluate the expressions one by one. So you can probably fake the behaviour by telling read.moments to read from somewhere else and showing different code than you really executed on the slide, but I don't think there's a way to honestly do what you want. You might be able to automate this, i.e. to write code that source()'s a file and echos the right tex code to make it look as though it was entered at the command line, but it would be messy. Duncan Murdoch Below is the slide in question in an executable example: \documentclass[dvipsnames,pdflatex,compress,beamer]{beamer} \usepackage{Sweave} ...snip... .541 .537.534 .35.367 .32 .555 .38 .358.359 .424.446 .325 .598 .452 @ \end{frame} \end{document} Not a Sweave solution, but that data set is available in psych: library(psych) data(bifactor) Thurstone Bill __ 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] lavaan diagram
Dear Sebastian, Yes. The problem is that the most recent version of psych 1-.0-94 was released before the most recent version of lavaan (0.4-7) I have updated the lavaan.diagram function in psych and will release it soon. In the meantime, you can get the update by sourcing it at http://personality-project.org/R/psych/R/lavaan.diagram.R e.g., source(http://personality-project.org/R/psych/R/lavaan.diagram.R;) I hope that helps. Bill At 9:03 PM -0600 3/6/11, Sebastián Daza wrote: Hi everyone, I get the following message when I try to get a diagram of a CFA: Error in lavaan.diagram(fit) : no slot of name GLIST for this object of class Fit Does anyone know what the problem is? Regards. -- Sebastián Daza sebastian.d...@gmail.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-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] PCA - scores
At 9:52 AM -0700 3/4/11, Shari Clare wrote: Hi Bill and Josh: When I run any principal code with scores=TRUE, I get the following Error: Error in principal (my.data,3,scores=TRUE) : unused argument (scores=TRUE) Thoughts? What version of psych are you using? Does it work on the example I sent (see below)? Thanks, Shari On 3-Mar-11, at 9:42 PM, William Revelle wrote: Shari, Josh partly answered your question, but his example did not include rotation because he took out just one factor. Try: require(psych) mt.pc - principal(mtcars,3,scores=TRUE) #this gives you the varimax rotated first 3 principal components #pc.scores - mt.pc$scores #here are the scores biplot(mt.pc)#show the data as well as the principal components in a biplot Bill At 5:15 PM -0800 3/3/11, Joshua Wiley wrote: Hi Shari, Yes, please look at the documentation for principal. You can access this (assuming you have loaded psych) by typing at the console: ?principal note the logical argument scores. Here is a small example: ## require(psych) require(GPArotation) dat - principal(mtcars[, c(mpg, hp, wt)], nfactors = 1, rotate = oblimin, scores = TRUE) dat$scores ## Cheerio, Josh On Thu, Mar 3, 2011 at 1:02 PM, Shari Clare mailto:scl...@ualberta.cascl...@ualberta.ca wrote: I am running a PCA, but would like to rotate my data and limit the number of factors that are analyzed. I can do this using the principal command from the psych package [principal(my.data, nfactors=3,rotate=varimax)], but the issue is that this does not report scores for the Principal Components the way princomp does. My question is: Can you get an output of scores using principal OR, is there a way to limit the number of factors that are included when you use princomp? Thanks, Shari Clare PhD Candidate Department of Renewable Resources University of Alberta mailto:scl...@ualberta.cascl...@ualberta.ca 780-492-2540 [[alternative HTML version deleted]] __ mailto:R-help@r-project.orgR-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-helphttps://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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/http://www.joshuawiley.com/ __ mailto:R-help@r-project.orgR-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-helphttps://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. __ 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] PCA - scores
Shari, Josh partly answered your question, but his example did not include rotation because he took out just one factor. Try: require(psych) mt.pc - principal(mtcars,3,scores=TRUE) #this gives you the varimax rotated first 3 principal components #pc.scores - mt.pc$scores #here are the scores biplot(mt.pc)#show the data as well as the principal components in a biplot Bill At 5:15 PM -0800 3/3/11, Joshua Wiley wrote: Hi Shari, Yes, please look at the documentation for principal. You can access this (assuming you have loaded psych) by typing at the console: ?principal note the logical argument scores. Here is a small example: ## require(psych) require(GPArotation) dat - principal(mtcars[, c(mpg, hp, wt)], nfactors = 1, rotate = oblimin, scores = TRUE) dat$scores ## Cheerio, Josh On Thu, Mar 3, 2011 at 1:02 PM, Shari Clare scl...@ualberta.ca wrote: I am running a PCA, but would like to rotate my data and limit the number of factors that are analyzed. I can do this using the principal command from the psych package [principal(my.data, nfactors=3,rotate=varimax)], but the issue is that this does not report scores for the Principal Components the way princomp does. My question is: Can you get an output of scores using principal OR, is there a way to limit the number of factors that are included when you use princomp? Thanks, Shari Clare PhD Candidate Department of Renewable Resources University of Alberta scl...@ualberta.ca 780-492-2540 [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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-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] barplot with errorbars
As the FAQ (http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-put-error-bars-or-confidence-bands-on-my-plot_003) says, there are about 5 different packages that will draw error bars. At 2:38 PM -0600 2/17/11, Aldi Kraja wrote: Hi Toby and Maria, I did a check on Toby's suggestion and it is not there: R version 2.12.1 (2010-12-16) ??barploterrbar No help files found with alias or concept or title matching 'barploterrbar' using fuzzy matching. Also I went to the following location which does not exist. http://www.dkfz.de/abt0840/whuber To Maria: here is a suggestion: to do the barplot with confidence intervals / errorbars: look at the following R news under www.r-project.org An introduction to using R's base graphics. (see following citation) on page 4 you will find explanations and code how to build bars with se. [62]Marc Schwartz. R Help Desk: An introduction to using R's base graphics. /R News/, 3(2):2-6, October 2003. [ bib | http http://CRAN.R-project.org/doc/Rnews/ | .pdf http://CRAN.R-project.org/doc/Rnews/Rnews_2003-2.pdf ] HTH, Aldi On 2/17/2011 10:08 AM, Toby Marthews wrote: If you google barplot with error bars you immediately find http://svitsrv25.epfl.ch/R-doc/library/prada/html/barploterrbar.html . Toby. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Lathouri, Maria [m.lathour...@imperial.ac.uk] Sent: 17 February 2011 16:00 To: r-help@r-project.org Subject: [R] barplot with errorbars Dear all I have six variables of the average metal concentrations Var1 4.77 Var2 23.5 Var3 5.2 Var4 12.3 Var5 42.1 Var6 121.2 I want to plot them as a barplot with error bars. Could you help me? Cheers Maria -- [[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] Creating covariance matrices for simple and complex factor structure
At 6:00 PM + 2/5/11, LOUDERMILK, BRANDON wrote: Hello all, I'm trying to create covariance matrices that, when processed via CFA methods (in the sem package) will produce exact fit with simple structure down to poor fit with cross loadings. What is the best way to do this? I don't really need to have the exact loop code, but maybe an explanation of how to make a few of the matrices or an explanation of the rationale behind performing this task would be of benefit. Thanks in advance. [[alternative HTML version deleted]] Brandon, See some of the simulation functions in the psych package. e.g., sim.congeneric, sim.structure, sim. circumplex, sim.simplex, etc. Bill __ 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] Re : Re : descriptive statistics
An alternative way of getting summary statistics by a grouping variable is to use describe.by in the psych package: using Jim Lemon's example: library(psych) testmat-data.frame(sample(1:14,50,TRUE),rnorm(50),runif(50)) #make up the data describe.by(test.mat,testmat[1]#get descriptive statistics At 8:17 AM -0800 12/13/10, effeesse wrote: what am I supposed to put into function(x)? The indicator for extracting the subgroups? data is the df. cluster={1,...,14}. This is how I was compiling: for (i in 1:14) { my.summary-data$cluster==i c(mean(?),var(?)) summary(var_A~cluster, fun=my.summary,data=data) summary(var_B~cluster, fun=my.summary,data=data) summary(var_C~cluster, fun=my.summary,data=data) summary(var_D~cluster, fun=my.summary,data=data) summary(var_E~cluster, fun=my.summary,data=data) summary(var_F~cluster, fun=my.summary,data=data) summary(var_G~cluster, fun=my.summary,data=data) } thanks for your patience. -- View this message in context: http://r.789695.n4.nabble.com/descriptive-statistics-tp3085197p3085651.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-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] Significance of the difference between two correlation coefficients
At 5:02 PM + 11/29/10, Adaikalavan Ramasamy wrote: Thanks for providing the example but it would be useful to know who I am communicating with or from which institute, but nevermind ... I don't know much about this subject but a quick google search gives me the following site: http://davidmlane.com/hyperstat/A50760.html Using the info from that website, I can code up the following to give the two-tailed p-value of difference in correlations: diff.corr - function( r1, n1, r2, n2 ){ Z1 - 0.5 * log( (1+r1)/(1-r1) ) Z2 - 0.5 * log( (1+r2)/(1-r2) ) diff - Z1 - Z2 SEdiff - sqrt( 1/(n1 - 3) + 1/(n2 - 3) ) diff.Z - diff/SEdiff p - 2*pnorm( abs(diff.Z), lower=F) cat( Two-tailed p-value, p , \n ) } diff.corr( r1=0.5, n1=100, r2=0.40, n2=80 ) ## Two-tailed p-value 0.4103526 diff.corr( r1=0.1, n1=100, r2=-0.1, n2=80 ) ## Two-tailed p-value 0.1885966 The p-value here is slightly different from the Vassar website because the website rounds it's diff.Z values to 2 digits. Regards, Adai See also r.test in the psych package which will test for the difference between two independent correlations as well as the more complicated case of two dependent correlations. r.test(n=100,r12=.5,r34=.4, n2=80) Correlation tests Call:r.test(n = 100, r12 = 0.5, r34 = 0.4, n2 = 80) Test of difference between two independent correlations z value 0.82with probability 0.41 r.test(n=100, .1,-.1,n2=80) r.test(n=100, .1,-.1,n2=80) Correlation tests Call:r.test(n = 100, r12 = 0.1, r34 = -0.1, n2 = 80) Test of difference between two independent correlations z value 1.31with probability 0.19 Bill On 29/11/2010 15:30, syrvn wrote: Hi, based on the sample size I want to calculate whether to correlation coefficients are significantly different or not. I know that as a first step both coefficients have to be converted to z values using fisher's z transformation. I have done this already but I dont know how to further proceed from there. unlike for correlation coefficients I know that the difference for z values is mathematically defined but I do not know how to incorporate the sample size. I found a couple of websites that provide that service but since I have huge data sets I need to automate this procedure. (http://faculty.vassar.edu/lowry/rdiff.html) Can anyone help? Cheers, syrvn __ 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] display data as 1px dots in scatterplot ?
At 4:46 AM -0800 11/21/10, madr wrote: By default scatter-plot presents data by using circles, is there a way to make it 1px dots ? -- View this message in context: http://r.789695.n4.nabble.com/display-data-as-1px-dots-in-scatterplot-tp3052343p3052343.html Sent from the R help mailing list archive at Nabble.com. pch = . e.g., x - rnorm(100) plot(x,pch=.) Bill __ 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] Multi-line graph?
?matplot e.g., copy your data to the clipboard then library(psych) my.data - read.clipboard() my.data Tenth Fifth Third GG 112 152 168 EC 100 120 140 SQ 160 184NA SK 120 100 180 matplot(t(my.data),type=b) Bill At 10:27 AM -0700 10/15/10, barnhillec wrote: Hi, I am relatively new to R but not to graphing, which I used to do in Excel and a few other environments on the job. I'm going back to school for a PhD and am teaching myself R beforehand. So I hope this question is not unacceptably ignorant but I have perused every entry level document I can find and so far I'm out of luck. I'm trying to graph some simple music psychology data. Columns are musical intervals, rows are the initials of the subjects. Numbers are in beats per minute (this is the value at which they hear the melodic interval split into two streams). So here's my table: Tenth Fifth Third GG 112152 168 EC 100120 140 SQ 160 184NA SK 120 100 180 I want a multi-line graph where the intervals are on the X axis, and the y axis is the beats per minute, and each subject has a different line. In Excel this would be no problem but I am having trouble in R. The only way I can figure out how to plot this in R is if the columns or rows are taken as variables. But the variable is beats per minute. Any suggestions? I appreciate the help. -Eric -- View this message in context: http://r.789695.n4.nabble.com/Multi-line-graph-tp2997402p2997402.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-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] Scatterplot matrix - Pearson linear correlation and Density Ellipse
Dear ashz, Unfortunately, much of you want is not possible with the current implementation of pairs.panels. Since pairs.panels is adapted from the help file of pairs, you might try pairs and then add in the panel functions that do what you want. That the lm option does it what it does met a need of mine for a demo of the difference of regression slopes of X on Y versus Y on X. Your request is very reasonable and I will implement it in the next revision. To get the pairwise complete rather than pairwise, you can preprocess your data file with na.omit e.g., cfc - na.omit(cfcap[8:11]) pairs.panesl(cfc) At 1:37 PM -0700 10/3/10, ashz wrote: Hi, I used the pairs.panels() in pkg:psych and it is helpful. It saves time. but if I use this line: pairs.panels(cfcap[8:11], scale = FALSE, lm=TRUE,ellipses=TRUE, digits = 2 ) The results are: - The upper.panel does not show the pearson r but the lm data. Furthermore, can I use the pairwise.complete.obs method for the upper.panel. Can it be fixed? - Can I remove the histograms? Not as a call, but you change pairs.panels to draw just the densities by substituting panel.hist.density - function(x,...) { usr - par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h - hist(x, plot = FALSE) breaks - h$breaks; nB - length(breaks) y - h$counts; y - y/max(y) #rect(breaks[-nB], 0, breaks[-1], y,col=hist.col) # --- comment this line out tryd - try( d - density(x,na.rm=TRUE,bw=nrd,adjust=1.2),silent=TRUE) if(class(tryd) != try-error) { d$y - d$y/max(d$y) lines(d)} } in place of the current panel.hist.density function. - Can I control the eliipse alpha? Not yet. Good idea. Your requests are all very reasonable and will be added to my wish list of additions to pairs.panels. This will not happen for several weeks, however. Bill Thanks a lot. -- View this message in context: http://r.789695.n4.nabble.com/Scatterplot-matrix-Pearson-linear-correlation-and-Density-Ellipse-tp2763552p2953521.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-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] Matrix- create mean/min/max/stdev on column of matrix or rows?
to get mean, sd, min, max, trimmed mean, median, se, skew, and kurtosis of a matrix or data frame, try describe in the psych package. At 10:41 PM -0300 9/17/10, Henrique Dallazuanna wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 659 Try this: apply(m, 1, summary) # 1 or 2 On Fri, Sep 17, 2010 at 1:08 PM, Halabi, Anan anan.hal...@hp.com wrote: I made simulation with Weibull and create Matrix, How can I create mean/min/max/stdev on column or rows of matrix?, Thanks, __ 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. __ 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] Problem with cat() == A related question
At 3:45 PM -0400 9/14/10, jim holtman wrote: The problem is the 'cat' enclosing the 'print'; just get rid of the 'cat' -- that is what is causing the extra output On Tue, Sep 14, 2010 at 3:34 PM, Peng, C cpeng@gmail.com wrote: It is still visible even it is set invisible(NULL): fn1 - function(n = 5){ + mat - matrix(rnorm(5*5), 5, 5) + cat(print(mat)) + invisible(NULL)} fn1() [,1][,2] [,3][,4] [,5] [1,] -1.22767085 -1.41468587 -2.0156231 0.29732942 0.5755600 [2,] -0.16775996 -0.03780596 -0.9461079 0.91289175 0.1254273 [3,] 0.09696032 -0.75522210 -0.7494442 -0.21341669 1.7088194 [4,] 0.13535505 -1.09011005 -0.6074198 0.05342614 -1.1996344 [5,] 0.66474083 -2.62206248 0.1329972 0.06132865 0.5124778 -1.227671 -0.1677600 0.09696032 0.1353550 0.6647408 -1.414686 -0.03780596 -0.7552221 -1.09011 -2.622062 -2.015623 -0.9461079 -0.7494442 -0.6074198 0.1329972 0.2973294 0.9128917 -0.2134167 0.05342614 0.06132865 0.57556 0.1254273 1.708819 -1.199634 0.5124778 -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-cat-tp2538811p2539551.html Sent from the R help mailing list archive at Nabble.com. I think that what Peng was trying to do was print it without the column and row names mat - matrix(1:25,5,5) colnames(mat) - rownames(mat) - rep(,5) print(mat) 1 6 11 16 21 2 7 12 17 22 3 8 13 18 23 4 9 14 19 24 5 10 15 20 25 Bill __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Making plots in big scatterplot matrix large enough to see
Jocelyn, In a partial answer to your question, try setting gap=0 in the calls to pairs. This will make the plots closer together. (You might also find pairs.panels in the psych package useful, -- it implements one of the help examples for pairs to report the histogram on the diagonal and reports the correlations in the upper off diagonal). On a Mac, I just tried setting quartz(width=30, height=30) #make a big graphics window #then library(psych) my.data - sim.item(24) #create 500 cases of 24 variables pairs.panels(my.data, gap=0) #the gap =0 makes the plots right next to each other #And then save the graphics window as a pdf. I can open this in a pdf and scroll around pretty easily. Bill At 5:21 AM +0100 8/31/10, Jocelyn Paine wrote: I've got a data frame with 23 columns, and wanted to plot a scatterplot matrix of it. I called pairs( df ) where 'df' is my data frame. This did generate the matrix, but the plotting window did not expand to make the individual plots large enough to see. Each one was only about 10 pixels high and wide. I tried sending the plot to a file, with a high and wide image, by doing png( plot.png, width = 4000, height = 4000 ) but I got these errors: Error in png( plot.png, width = 4000, height = 4000 ) : unable to start device In addition: Warning messages: 1: In png( plot.png, width = 4000, height = 4000 ) : Unable to allocate bitmap 2: In png( plot.png, width = 4000, height = 4000 ) : opening device failed The messages aren't helpful, because they don't tell you _why_ R can't start the device, allocate it, or open it. The documentation for png says: Windows imposes limits on the size of bitmaps: these are not documented in the SDK and may depend on the version of Windows. It seems that width and height are each limited to 2^15-1. However, 2^15-1 is 32767, so that isn't the problem here. I tried various values for height and width. 2400 was OK, but 2500 wasn't. So it seems R can't produce plots that are more than about 2400 pixels square. This is with R 2.10.1. Why is png failing on big images? Also, what's the recommended way to make a file containing a scatterplot matrix when you have lots of variables? 'pairs' is a very useful function, but obviously one does need to be careful when doing this, and I don't know what experts would recommend. Do you loop round the variables plotting each pair to a different file? I was hoping that I could put them all into one very big image and view parts of it at a time. Thanks, Jocelyn Paine http://www.j-paine.org http://www.spreadsheet-parts.org +44 (0)7768 534 091 __ 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. -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] Draw a perpendicular line?
At 3:04 PM -0700 8/23/10, CZ wrote: Hi, I am trying to draw a perpendicular line from a point to two points. Mathematically I know how to do it, but to program it, I encounter some problem and hope can get help. Thanks. I have points, A, B and C. I calculate the slope and intercept for line drawn between A and B. I am trying to check whether I can draw a perpendicular line from C to line AB and get the x,y value for the point D at the intersection. Assume I get the slope of the perpendicular line, I will have my point (D) using variable x and y which is potentially on line AB. My idea was using |AC|*|AC| = |AD|*|AD|+ |CD|*|CD|. I don't know what function I may need to call to calculate the values for point D (uniroot?). This is easier than you think. Think of the x,y coordinates of each point : Then, the slope is slope = rise/run = (By- Ay)/(Bx- Ax) The Dx coordinate = Cx and the Dy = (Dx - Ax) * slope Then, to draw the line segment from C to D lines(C,D) In R: A - c(2,4) B - c(4,1) C - c(8,10) slope -( C[2]- A[2])/(C[1]-A[1]) #rise/run D - c(B[1],(B[1]-A[1])*slope + A[2]) # find D my.data - rbind(A,B,C,D) colnames(my.data) - c(X,Y) my.data#show it plot(my.data,type=n) #graph it without the points text(my.data,rownames(my.data)) #put the points in segments(A[1],A[2],C[1],C[2]) #draw the line segments segments(B[1],B[2],D[1],D[2]) Bill Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Draw-a-perpendicular-line-tp2335882p2335882.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-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] How to measure correlations in terms of distance and draw them on a 2-dimmentional plot?
Weijian, Look at multidimensional scaling functions such as cmdscale or isoMDS (in MASS) or factor analysis (e.g., factanal in core R or fa in the psych package) or item cluster analysis (ICLUST, also in psych). What you will need to think about is how many dimensions best represent the 10 variables. .One will just put them on a line, 2 might or might not work depending upon your data, 3 ... In terms of a distance matrix, in order to use an mds function, first you will need to convert correlations to distances try distance = sqrt (2 *(1-r))., Bill At 2:47 PM -0700 8/18/10, weijian21cn wrote: Probably I put it too complicated. I just try to draw 10 points on a plot. Each point stand for one variable. If two variables are highly correlated, the corresponding dots are to be drawn closer. Say, variable X1, X2, X3, are highly correlated among them, so they will be clustered; variables X4, X5, X6 are not much correlated with X1,X2, X3, so X4-X5 are drawn far away from X1-X3. In addition, if corr(X1, X2) corr(X2,X3), the plot can show distance(X1, X2) distance(X2, x3). Do you know if R has such a package? Or I may use some plot function from cluster analysis? Thank you! Weijian -- View this message in context: http://r.789695.n4.nabble.com/How-to-measure-correlations-in-terms-of-distance-and-draw-them-on-a-2-dimmentional-plot-tp2330413p2330442.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-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] problem with building package on CRAN
Dear friends, I have just gotten a strange error message back from Uwe saying that the most recent version of psych failed to pass R CMD check for Windows. The error message was less than helpful, in that it seems to have failed when trying to include the Rcpp library, which I do not directly call. (see below) * using log directory 'd:/Rcompile/CRANpkg/local/2.11/psych.Rcheck' * using R version 2.11.1 (2010-05-31) * using session charset: ISO8859-1 * checking for file 'psych/DESCRIPTION' ... OK * this is package 'psych' version '1.0-90' * checking package name space information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking whether package 'psych' can be installed ... ERROR Installation failed. The installation logfile: -Id:/Rcompile/CRANpkg/lib/2.11/Rcpp/include I do have several suggested packages (polycor, GPArotation, MASS, graph, Rgraphviz, mvtnorm, Rcsdp), but none of these are actually required. My examples all ask if the suggested packages are available and then do not call them if they are not. Any suggestions on what to do would be appreciated. Thanks. Bill -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] Beginning Eigen System question.
Kevin, At 3:32 PM -0700 6/23/10, rkevinbur...@charter.net wrote: Forgive me if I missunderstand a basic Eigensystem but when I present the following matrix to most any other LinearAlgebra system: 1 3 1 1 2 2 1 1 3 I get an answer like: //$values //[1] 5.00e+00 1.00e+00 -5.536207e-16 //$vectors // [,1] [,2] [,3] //[1,] 0.5773503 -0.8451543 -0.9428090 //[2,] 0.5773503 -0.1690309 0.2357023 //[3,] 0.5773503 0.5070926 0.2357023 But R gives me: //$values //[1] 5.00e+00 1.00e+00 -5.536207e-16 //$vectors // [,1] [,2] [,3] //[1,] -0.5773503 -0.8451543 -0.9428090 //[2,] -0.5773503 -0.1690309 0.2357023 //[3,] -0.5773503 0.5070926 0.2357023 The only difference seems to be the sign on the first eigen vector. What am I missing? The sign of the eigen vectors is arbitrary. From ?eigen Recall that the eigenvectors are only defined up to a constant: even when the length is specified they are still only defined up to a scalar of modulus one (the sign for real matrices). Bill Kevin __ 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] Plotting confidence intervals of two response on same graph (panel).
Kim, It is possible that error.crosses in the psych package will do what you want. Bill At 9:25 AM -0400 6/17/10, Kim Jung Hwa wrote: Hello! I would like to draw a graph like the following: http://www.optics.rochester.edu/workgroups/cml/opt307/spr04/pavel/plot_small.jpg Aim is to plot confidence intervals of treatments for X(=response1) and Y(=response2) axis simultaneously to visualize aggreement of confidence interval for two responses. Can anyone please provide me some direction to start with? Thanks! -- Kim. [[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. -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] Intra-Class correlation psych package missing data
Ross, My apologies, I just discovered your email (from April) to the R-help list serve asking about ICC in psych. ICC does not remove missing data but rather lets the ANOVA handle it. It is probably more appropriate work on complete cases (as does the icc in the irr package). that is my.data - na.omit(my.data) ICC(my.data) I have just fixed ICC so that it will by default use na.omit and thus work on complete cases.This will be in the psych 1.0.89 release which should be ready by this weekend. Bill At 4:21 AM -0800 4/8/10, RCulloch wrote: Hello R users, and perhaps William Revelle in particular, I'm curious as to how ICC deals with missing data, so for example you are sampling individuals over set periods in time and one individual is missing or was not recaptured at that given time point - leading to NA in the dataset. My thought was that it should then omit data by individual, but I'm not convinced that that is what it is doing? You are completely correct. Does anyone know, I have looked at ?ICC but there is no information there, apologies if I have missed it in any other help file, I have looked, but to no avail! Thanks in advance, Ross -- View this message in context: http://n4.nabble.com/Intra-Class-correlation-psych-package-missing-data-tp1773942p1773942.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-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] color of histgram in Psych package (pairs.panels)
At 10:56 AM +0800 6/8/10, elaine kuo wrote: Hello, I searched the archives but found no answers. How to modify the hisgram color of function pairs.panels of Psych package ? I tried col() but it was the line color modified. Thanks. Elaine Elaine, Good question. Right now, without going into the function and changing the color in the col=cyan line in the pairs.hist.density function and then copying the entire set of functions back into your workspace, it can not be done. (That is to say, it can be done, but it is a pain.) I am about to release psych version 1.0-89 , probably this weekend, and have added this feature to it. In the meantime, if you want the fixed version of pairs.panels, I can just send it to you. Bill __ 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. -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] Error Bar Issues
Dear Beloitstudent; Although Ben Bolker will have to give you the definitive answer, the following will do what I think you want to do. library(plotrix) #for those of us who don't know where plotCI comes from #give us the data: Saline - structure(list(Time = c(-20L, NA, 30L, 45L, 60L, 80L, 110L, 140L, 200L, 260L, 320L), Average = c(0, NA, 0, 3.227902, 5.04, 6.107491, 6.968231, 7.325713, 7.875194, 6.513927, 4.204342), SEM = c(0, NA, 0, 0.7462524, 1.1623944, 1.5027762, 1.3799637, 1.2282053, 1.1185175, 0.5386359, 0.6855906)), .Names = c(Time, Average, SEM), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) # First draw the points plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], err=y, pt.bg=par(bg),pch=21, cex=1.5 ,gap=0, sfrac=0.005, xlim=c(-20,340),xaxp=c(-20,320,17), xlab=Time (min), ylim=c(0,12), yaxp=c(0,12,12), ylab=Arterial Plasma Acetaminophen (µg/mL), las=1, font.lab=2)#draws the points plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], err=y, pt.bg=par(bg),pch=21, cex=1.5 ,gap=0, sfrac=0.005, xlim=c(-20,340),xaxp=c(-20,320,17), ylim=c(0,12), yaxp=c(0,12,12), las=1, font.lab=2,add=TRUE,type=o) #puts the lines in and gives a message You will get a warning message the type is obsolete, but at least you have your graph. Bill At 3:51 PM -0700 6/5/10, beloitstudent wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 4586 Thanks for the suggestion...but R still doesn't like it. Now I have 3 error messages. It seems to dislike my *err=y* command. I'm going to continue trying. Thanks for your help! If you happen to spot anything else, please let me know! thanks! beloitstudent On Sat, Jun 5, 2010 at 5:16 PM, Joris FA Meys [via R] ml-node+2244611-1554261936-278...@n4.nabble.comml-node%2b2244611-1554261936-278...@n4.nabble.com wrote: you can't refer to an argument within a function call. Try uiw - Saline[,3] plotCI(x=Saline [,1],y=Saline [,2], uiw=uiw, liw=uiw, err=y, pch=21, pt.bg=par(bg), cex=1.5, lty=1, type=o, gap=0, sfrac=0.005, xlim=c(-21,340),xaxp=c(-20,320,11), xlab=Time (min), ylim=c(0,12), yaxp=c(0,12,11), ylab=Arterial Plasma Acetaminophen (µg/mL), las=1, font.lab=2, add=TRUE) Cheers Joris On Sat, Jun 5, 2010 at 6:09 PM, beloitstudent [hidden email]http://user/SendEmail.jtp?type=nodenode=2244611i=0 wrote: Hello all, I am an undergraduate student who is having syntax issues trying to get error bars on my graph. This is the data, which I assigned the name Saline to. Time Average SEM 1 -20 0.00 0.000 2 330 0.00 0.000 445 3.227902 0.7462524 560 5.04 1.1623944 680 6.107491 1.5027762 7 110 6.968231 1.3799637 8 140 7.325713 1.2282053 9 200 7.875194 1.1185175 10 2606.513927 0.5386359 11 3204.204342 0.6855906 This is the command that I typed in to get my error bars. plotCI(x=Saline [,1],y=Saline [,2], uiw=Saline [,3], liw=uiw, err=y, pch=21, pt.bg=par(bg), cex=1.5, lty=1, type=o, gap=0, sfrac=0.005, xlim=c(-21,340),xaxp=c(-20,320,11), xlab=Time (min), ylim=c(0,12), yaxp=c(0,12,11), ylab=Arterial Plasma Acetaminophen (µg/mL), las=1, font.lab=2, add=TRUE) And this is the error message I keep getting Error in plotCI(x = Saline[, 1], y = Saline[, 2], uiw = Saline[, 3], liw = uiw, : object 'uiw' not found In addition: Warning message: In if (err == y) z - y else z - x : the condition has length 1 and only the first element will be used Now, to me, the command seems correct. I want the error bars to show up where the points on my graph are...so the x coordinates should be my time (aka Saline [1]) and the y coordinates should be my Averages (aka Saline [2]) and my upper and lower limits to my confidence interval should be the SEM from Saline [3], but something is wrong with this and I cannot figure out what it is. If anyone has suggestions I would be very grateful. Thanks for your help! beloitstudent -- View this message in context: http://r.789695.n4.nabble.com/Error-Bar-Issues-tp2244335p2244335.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] http://user/SendEmail.jtp?type=nodenode=2244611i=1mailing 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. -- Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 [hidden email] http://user/SendEmail.jtp?type=nodenode=2244611i=2 --- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php __
Re: [R] Cohen's Kappa for beginners
Peter, Scot, Jim, and Jason, Thanks for the various solutions to Jason's problem. In the next release of psych I will a) document how to use non-numeric categorical variables (e.g., red, blue, etc.) when using cohen.kappa, b) suggest that cbind does the job (Peter's solution), c) make it work with data.frames without the need to do the recode that Scot did. For the record, here is the output you get by using cbind: ck - cohen.kappa(cbind(x,y)) ck Call: cohen.kappa1(x = x, w = w, n.obs = n.obs, alpha = alpha) Cohen Kappa and Weighted Kappa correlation coefficients and confidence boundaries lower estimate upper unweighted kappa 0.098 0.6 1.10 weighted kappa -0.693 0.0 0.69 Number of subjects = 4 ck$agree #show the table of matches x2f x1f blue red yellow blue 0.25 0.00 0.00 red0.00 0.50 0.00 yellow 0.25 0.00 0.00 Bill At 7:57 AM -0600 5/25/10, Peter Ehlers wrote: cohen.kappa(cbind(x,y)) works for me. -Peter Ehlers On 2010-05-25 7:42, Scot W. McNary wrote: Hi, It doesn't seem happy with non-numeric data in the data frame version. Maybe a recode would work? x1 - c(1, 2, 3, 1) y1 - c(1, 3, 3, 1) cohen.kappa(data.frame(x = x1, y = y1)) Call: cohen.kappa1(x = x, w = w, n.obs = n.obs, alpha = alpha) Cohen Kappa and Weighted Kappa correlation coefficients and confidence boundaries lower estimate upper unweighted kappa 0.098 0.60 1.1 weighted kappa 0.601 0.86 1.1 The unweighted kappa is .60. I also tried to create the p x p table version, thinking that it would be unhappy with less than a p x p table. The example dataset produces a 3 x 2 table, so this pads it out to a 3 x 3: x - factor(x) y - factor(y, levels = c(blue, red, yellow)) table(x,y) y x blue red yellow blue 1 0 0 red 0 2 0 yellow 1 0 0 cohen.kappa(table(x,y)) Call: cohen.kappa1(x = x, w = w, n.obs = n.obs, alpha = alpha) Cohen Kappa and Weighted Kappa correlation coefficients and confidence boundaries lower estimate upper unweighted kappa 0.098 0.6 1.10 weighted kappa -0.693 0.0 0.69 Number of subjects = 4 The unweighted kappa is the same as above and as found by Jim with other packages. Scot On 5/25/2010 7:31 AM, Jim Lemon wrote: On 05/25/2010 06:01 PM, Jason Priem wrote: Hi, I've got two vectors with ratings from two coders, like this: x-c(red, yellow, blue, red) #coder number 1 y-c(red, blue, blue, red) #coder number 2 I want to find Cohen's Kappa using the wkappa function in the psych package. The only example in the docs is using a matrix, which I'm afraid I don't understand--I don't know how to get there from what I've got. Could anyone point me in the right direction? Thanks! Hi Jason, You're not alone. I tried to work out how to run this and it took a while. Both kappa2 in the irr package: kappa2(cbind(x,y)) and classAgreement in the e1071 package: classAgreement(table(x,y)) produce a kappa of 0.6. I was unable to work out how to use the wkappa function in the psych package: wkappa(table(x,y)) The above led to a kappa of -0.8. Although wkappa is presented as a test of the reliability of ratings of nominal level data, the example uses numeric data. Jim __ 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] Cohen's Kappa for beginners
Jason, At 9:55 AM -0700 5/25/10, Jason Priem wrote: Thanks for you quick responses, all! Bill, it looks like that's just what I want, but I'm not sure where you're getting the cohen.kappa() function. The only function I could find by that name is in the concord library, and it gives me: x-c(red, yellow, blue, red) #coder number 1 y-c(red, blue, blue, red) #coder number 2 ck - cohen.kappa(cbind(x,y)) Error in counts[i, j] - sum(scores[i, ] == score.levels[j], na.rm = TRUE) : subscript out of bounds In addition: Warning messages: 1: NAs introduced by coercion 2: NAs introduced by coercion wkappa in the psych lib gives me Error in tr(x) : m must be a square matrix Sorry for the confusion. cohen.kappa was introduced in the psych package version of 1.0.86 in March. The current release is 1.0.88. Bill -- View this message in context: http://r.789695.n4.nabble.com/Cohen-s-Kappa-for-beginners-tp2229658p2230348.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-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] simple data import of .csv
Hello, I am a complete beginner to R. I use a mac and want to import and read a .csv dataset stored as .csv file. I understand I eventually enter - read.csv(size.csv, header=T) , but I can't get R to find my file, which is called size.csv and located /Users/davidoconnor/Desktop/Eart-125/size.csv Thank you very much! David -- View this message in context: http://n4.nabble.com/simple-data-import-of-csv-tp1835620p1835620.html Sent from the R help mailing list archive at Nabble.com. Two solutions: To find the file, use file.choose() e.g., my.file.name - file.choose()#and then use the normal mac tools to find the file my.data - read.csv(my.file.name,header=TRUE) or, if you want to just read it from the clipboard: library(psych) my.data - read.clipboard.csv()#after copying the data to the clipboard Bill __ 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. -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] strange behavior of matrix
Dear R list, I have discovered a seemingly peculiar feature when using a matrix to index itself (yes, this is strange code, which I have now modified to be more reasonable). #this makes sense s - matrix(1:3,nrow=1) s[s]#all three elements are shown #but when I try s - matrix(1:2,nrow=1) s[1] #fine, the first element is shown s[2] #fine, the second element is shown s[s] #just the second element is shown -- this is peculiar #But doing it by columns works for both cases s - matrix(1:3,ncol=1) s[s]#all three elements are shown #and when I try the same problem down a column s - matrix(1:2,ncol=1) s[1] #fine s[2] #fine s[s] #this shows both elements as would be expected #clearly since I have just one dimension, it would have been better to s - 1:2 s[s] #which works as one would expect. Or, using the array function we get the same problem. s - array(1:2,dim=c(1,2)) s[s] [1] 2 s - array(1:2,dim=c(2,1)) s[s] [1] 1 2 sessionInfo() R version 2.11.0 Under development (unstable) (2010-03-24 r51389) i386-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] psych_1.0-87 I think this is unexpected behavior. Best wishes, Bill -- 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 6 minutes to midnight http://www.thebulletin.org __ 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] error bars
Iasonas, In response to PS.1 try error.bars in the psych package. Bill At 1:04 AM -0700 3/30/10, Iasonas Lamprianou wrote: Dear friends, I have a statistical question. Sometimes, if I compare boys to girls on a specific variable, the error bars (confidence interval of means) seem to overlap slightly. Still, when I run a t-test, I find statistically significant differences. The rule is clear: if the confidence intervals do not overlap, then there is statistically significant difference. But if they overlap slightly, we have to use a t-test to know for sure if the the two means differ significantly. The point is: is there a rule of thumb to say, for example, if the overlap is less than 20% of the length of the standard error, then a t-test would give significant results? thank you for your time P.S.1 is there an easy way to plot error bars in R? P.S.2 an interesting discussion about this - highly recommended to read it - can be found at http://scienceblogs.com/cognitivedaily/2007/03/ill_bet_you_dont_understand_er.php jason Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk __ 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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] Plot interaction in multilevel model
I think both graphs will follow the same technique. This is partly laid out in how to do graphs of anova output at http://personality-project.org/r/r.plotregressions.html (which is part of the short (and out of date) guide to R for psychologists) http://personality-project.org/r/ At 6:39 PM -0800 3/5/10, dadrivr wrote: I am trying to plot an interaction in a multilevel model. Here is some sample data. In the following example, it is longitudinal (i.e., repeated measures), so the outcome, score (at each of the three time points), is nested within the individual. I am interested in the interaction between gender and happiness predicting score. id - c(1,1,1,2,2,2,3,3,3) age - c(10,15,20,10,15,20,10,15,20) gender - c(1,1,1,0,0,0,1,1,1) happiness - c(50,30,25,70,65,80,70,40,60) score - c(180,140,110,240,220,280,150,140,130) mydata - data.frame(id,age,gender,happiness,score) I am looking to create two plots: 1. A plot with score on the y-axis, happiness on the x-axis, gender as the moderating variable, and a linear best-fit line for each level of gender (male female). Here is my attempt, but I don't know how to make it into linear best-fit lines: with(mydata,interaction.plot(happiness,gender,score)) color - c(red,blue) plot(happiness,score,col=color[gender+1]) by(mydata,gender,function(x) abline(lm(x$score~x$happiness))) 2. A plot with score on the y-axis, age on the x-axis, and 4 different best fit lines representing the following levels of gender and happiness (male hi happy, male lo happy, female hi happy, female lo happy). Here is my attempt, but I don't know how to create the 4 different best-fit lines representing the 4 different interaction levels: with(mydata,interaction.plot(age,gender,score)) by(mydata,gender*age,function(x) abline(lm(x$score~x$happiness))) Any ideas? Any help would be greatly appreciated with these two plots. Thanks so much! I hope this does what you want. Bill -- View this message in context: http://n4.nabble.com/Plot-interaction-in-multilevel-model-tp1580370p1580370.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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] block matrices
At 1:06 PM -0300 2/24/10, Kjetil Halvorsen wrote: see below. On Wed, Feb 24, 2010 at 12:56 PM, Gustave Lefou gustave5...@gmail.com wrote: Dear all, I do not know how to deal with block matrices in R. For example I have 3 matrices A, B and C. And I want to produce a new matrix of this form ( A B 0 ) ( 0 0 C ) where A, B and C are one-row matrices. cbind(A,B,0) or maybe cbind(a,B,rep(0, 12)) cbind(rep(0,2), C) For the case where you have A and B matrices library(psych) C - super.matrix(A,B) will produce A 0 0 B e.g. A - matrix(1:4,2,2) B - matrix(5:16,3,4) C - super.matrix(A,B) C X1 X2 Y1 Y2 Y3 Y4 Vx1 1 3 0 0 0 0 Vx2 2 4 0 0 0 0 Vy1 0 0 5 8 11 14 Vy2 0 0 6 9 12 15 Vy3 0 0 7 10 13 16 Bill Apart from A, B and C, all the coefficients are 0. Is there an easy solution in R for every block matrices ? Combine rbind and cbind: ?rbind Kjetil Thanks for your help, Gustave P.S. : I have had a look at a function called zoo which looked quite complicated to me. [[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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] tree-drawing in R ?
try Rgraphviz diagram At 6:07 PM + 2/15/10, Oliver Kullmann wrote: Hello, I wonder whether binary (rooted) trees with simple labels (say, integers) can be drawn by some R-package? Couldn't find one. Just to make sure (since trees can be many things): I mean those computer-science creatures, with roots and subtrees. Thanks for your consideration in any case Oliver P.S. Perhaps there is some graph-drawing package? (Here a graph consists of vertices and connecting edges.) __ 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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] Error analysis for circular data
See the packages: CircSpatial CircStats circular At 10:58 PM +0100 2/15/10, Francisco Javier Santos Alamillos wrote: Dear R users, I would like to know if it is possible to calculate the Mean Error (ME), the Root Mean-squared error (RMSE) and absolute error (MAE) for two temporal series of directional data. Where Can I get documentation about it? Thanks in advance [[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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] summary statistics for grouped data
At 6:44 PM +0100 2/12/10, Søren Højsgaard wrote: You might find the summaryBy function in the doBy package useful. Regards Søren see also the describe.by function in the psych package. Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] P#229; vegne af jose romero [jlauren...@yahoo.com] Sendt: 12. februar 2010 18:23 Til: r-help@r-project.org Emne: [R] summary statistics for grouped data Hello list: Is there an easy way (preferably through one of the standard R packages) of obtaining summary statistics for grouped data? I could split the data into classes by hist, and then progressively calculate all the columns i need to obtain the mean and standard deviation, but i was looking for a single function that could do that with a data vector. Thanks in advance, jose romero [[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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] Calculation of Central Moments
At 9:09 AM -0500 12/1/09, Jorge Ivan Velez wrote: Hi Maithili, Here is a suugestion: R install.packages('fBasics') R require(fBasics) R set.seed(123) R x - rnorm(100) R basicStats(x) HTH, Jorge or, try the describe function in psych. However, neither fBasics nor describe will report the mode. On Tue, Dec 1, 2009 at 2:08 AM, Maithili Shiva wrote: Dear R helpers If for a given data, I need to calculate Mean, Standard Deviation, Mode, Median, Skewness, Kurtosis, is there any package in R, which will calculate these moments? Individually I can calculate these, but if there is any function which will calculate these at a stretch, please let me know. Maithili The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. [[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. [[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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] Structural Equation Models(SEM)
Ralf, If you are representing this as a factor model, you need to have the factors lead to the variables: model.RLIM - specify.model() f1 - R , laddR, NA f1 - L, laddL, NA f1 - I, laddI, NA f1 - M, laddM, NA R - R, dR,NA L - L, dL,NA I - I, dI,NA M - M, dM,NA f1 - f1, df1,NA sem(mod1,tcv,101) Model Chisquare = 5.955411 Df = 3 F1RF1LF1Ix1ex2ex3ex4e 0.20301850 0.28443881 0.39421470 0.10734247 0.09951485 0.09105800 0.31702970 Iterations = 24 For a simple way to create the sem commands from an exploratory factor analysis, you might want to look at the psych package and the vignette: psych_for_sem. e.g., library(psych) f1 - fa(tcv) #do the exploratory factor analysis mod1 - structure.diagram(f1,errors=TRUE) #draw the path diagram from the model and create the sem commands mod1 Path Parameter StartValue 1 MR1-RF1R 2 MR1-LF1L 3 MR1-IF1I 4 R-R x1e 5 L-L x2e 6 I-I x3e 7 M-M x4e 8 MR1-MR1 fixed 1 sem(mod1,tcv,101) #do the sem Model Chisquare = 5.955411 Df = 3 F1RF1LF1Ix1ex2ex3ex4e 0.20301850 0.28443881 0.39421470 0.10734247 0.09951485 0.09105800 0.31702970 Iterations = 24 Best wishes, Bill At 6:23 PM +0200 11/25/09, Ralf Finne wrote: Hi R-colleagues. In the sem-package i have a problem to introduce hidden variables. As a simple example I take an ordinary factor analysis. The program: cmat=c(0.14855886, 0.05774635, 0.08003300, 0.04900990, 0.05774635, 0.18042029, 0.11213013, 0.03752475, 0.08003300, 0.11213013, 0.24646337, 0.03609901, 0.04900990, 0.03752475, 0.03609901, 0.31702970) rn=c(R,L,I,M) cn=c(R,L,I,M) tcv=matrix(cmat,nrow=4,ncol=4,dimnames=list(rn,cn)) model.RLIM - specify.model() R - f1, laddR, NA L - f1, laddL, NA I - f1, laddI, NA M - f1, laddM, NA R - R, dR,NA L - L, dL,NA I - I, dI,NA M - M, dM,NA f1 - f1, df1,NA sem.RLIM=sem(model.RLIM,tcv,101) The output: Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent In addition: Warning messages: 1: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : singular Hessian: model is probably underidentified. 2: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : refitting without aliased parameters. I use R version 2.10.0 (2009-10-26) under Windows XP sem_0.9-19 version. Where did I make a mistake? Have anyone of you knowledge of any other package doing similar things like Confirmative Factor Analysis Ralf Finne Novia University of Applied Science Vasa Finland __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] R 2.10 memory leak on OS X
-[NSDistantObject forwardInvocation:] + 329 6 com.apple.CoreFoundation0x96ab784a ___forwarding___ + 986 7 com.apple.CoreFoundation0x96ab78b2 _CF_forwarding_prep_0 + 50 8 org.R-project.R 0xda65 -[RController readThread:] + 245 9 com.apple.Foundation0x94447dfd -[NSThread main] + 45 10 com.apple.Foundation0x944479a4 __NSThread__main__ + 308 11 libSystem.B.dylib 0x97473155 _pthread_start + 321 12 libSystem.B.dylib 0x97473012 thread_start + 34 Thread 0 crashed with X86 Thread State (32-bit): eax: 0x3c706f74 ebx: 0x96a690fe ecx: 0x0001 edx: 0x0007 edi: 0x00067ee2 esi: 0xf1c0a03d ebp: 0xbfffe6f8 esp: 0xbfffe6f0 ss: 0x001f efl: 0x00010282 eip: 0x07c7 cs: 0x0017 ds: 0x001f es: 0x001f fs: 0x gs: 0x0037 cr2: 0x00067ee2 #-- -- View this message in context: http://old.nabble.com/R-2.10-memory-leak-on-OS-X-tp26422294p26422294.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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] correlation help
Adrian, To find all the correlations between columns of a matrix and to find their individual significance levels (questionable given that you are doing many correlations) use either the rcorr function in the Hmisc package or the corr.test function in the psych package. Bill \At 6:19 PM -0400 9/20/09, Adrian Johnson wrote: thank you john. however, I am finding it difficult to automate on a matrix. Pardon my ignorance in R computing: I do not know how to automate on a matrix. If I do the following it works: x = cor.test(d6[1,],d6[2,]) x Pearson's product-moment correlation data: d6[1, ] and d6[2, ] t = 10.5196, df = 10, p-value = 9.973e-07 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8520623 0.9883592 sample estimates: cor 0.9576655 If I want to run it on all rows, I do not know how to do it. I tried following, lapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) sapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) for(i in 1:14659){ + k = i+1 + cor.test(d6[i,],d6[k,]) + x = cor.test(d6[i,],d6[k,]) + return(x)} Error: no function to return from, jumping to top level I appreciate your help. thank you. Adrian On Sun, Sep 20, 2009 at 6:17 PM, Adrian Johnson oriolebaltim...@gmail.com wrote: thank you john. however, I am finding it difficult to automate on a matrix. Pardon my ignorance in R computing: I do not know how to automate on a matrix. If I do the following it works: x = cor.test(d6[1,],d6[2,]) x Pearson's product-moment correlation data: d6[1, ] and d6[2, ] t = 10.5196, df = 10, p-value = 9.973e-07 alternative hypothesis: true correlation is not equal to 0 95 percent confidence interval: 0.8520623 0.9883592 sample estimates: cor 0.9576655 If I want to run it on all rows, I do not know how to do it. I tried following, lapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) sapply(d6,cor.test) Error in cor.test.default(X[[1L]], ...) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) for(i in 1:14659){ + k = i+1 + cor.test(d6[i,],d6[k,]) + x = cor.test(d6[i,],d6[k,]) + return(x)} Error: no function to return from, jumping to top level I appreciate your help. thank you. Adrian On Sun, Sep 20, 2009 at 5:13 PM, John Kane jrkrid...@yahoo.ca wrote: ?cor ?cor.test --- On Sun, 9/20/09, Adrian Johnson oriolebaltim...@gmail.com wrote: From: Adrian Johnson oriolebaltim...@gmail.com Subject: [R] correlation help To: r-help@r-project.org Received: Sunday, September 20, 2009, 5:00 PM Dear group, I have a matrix like the following: Name Sample1 sample2sample3 sample4 . sample(n) nm110.5 13.5 30 31 nm2 8 11 34 29 nm3 9 10.3 27.8 35 nm(j) I want to be able to calculate correlation between all pairs of names. For example (nm1,nm2), (nm1,nm3), (nm1,nmj), (nm2,nm3), (nm2,nmj) Then I want to calculate the significance of correlation using t-score or p-value. I can calculate correlation coeffecient in excel but not significance in both excel and R. I want to be able to do it in R, I appreciate your help. thank you. Ad. __ 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. __ Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail. Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r
[R] Alternatives to Rgraphviz -- request suggestions
Dear R-helpers, Can anyone suggest a useful alternative to Rgraphviz? I am trying to create fairly simple graphs showing the structures of a hierarchical cluster analysis or of a structural equation model. That is, I need to be able to control the shape (rectangles vs ovals) of a limited number ( several hundred) of nodes, connect them with edges that have values (usually numeric but sometimes text) and produce pretty output. I want to be able to force nodes to be on side or the other of the graph (sometimes, some on one side, others on the other side) and to minimize the number of edge crossings. I have been using Rgraphviz as a recommended but not required package for my psych package for several years but remain frustrated by the difficulties some users have installing Rgraphviz from BioConductor as well as by recent problems with graphviz itself (it will not install on Snow Leopard for the Mac). When Rgraphviz works, it is wonderful. However, PC users in particular seem to have problems installing it and now with Snow Leopard I can not get it work either. Does anyone have a recommended graphics packages that has at least some of the features of Rgraphviz (and hopefully, fewer of the difficulties). Thanks to all for your suggestions. Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] Fastest Way to Divide Elements of Row With Its RowSum
At 2:40 PM +0900 9/17/09, Gundala Viswanath wrote: I have a data frame (dat). What I want to do is for each row, divide each row with the sum of its row. The number of row can be large 1million. Is there a faster way than doing it this way? datnorm; for (rw in 1:length(dat)) { tmp - dat[rw,]/sum(dat[rw,]) datnorm - rbind(datnorm, tmp); } - G.V. datnorm - dat/rowSums(dat) this will be faster if dat is a matrix rather than a data.frame. Bill __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] Winsorized mean and variance
Roberto, Try winsor in the psych package. Bill At 10:21 AM -0400 8/27/09, Roberto Perdisci wrote: This is of great help, thanks! Roberto On Thu, Aug 27, 2009 at 7:20 AM, Jim Lemonj...@bitwrit.com.au wrote: Roberto Perdisci wrote: Hello everybody, after searching around for quite some time, I haven't been able to find a package that provides a function to compute the Windorized mean and variance. Also I haven't found a function that computes the trimmed variance. Is there any such package around? Hi Roberto, The Winsorized variance is similar to the trimmed variance, except that the extreme values are substituted rather than dropped. Define the quantiles within which you want to retain the original values and then substitute the values at the quantiles for all values more extreme in the respective sign direction. Like this: testdat-rnorm(20) winsorVar-function(x,probs=c(0.05,0.95)) { xq-quantile(x,probs=probs) x[x xq[1]]-xq[1] x[x xq[2]]-xq[2] return(var(x)) } Jim __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] intra-class correlation? coherence among multiple ordinal responses
At 6:15 PM -0400 8/21/09, Daniel Malter wrote: I have a quick statistical question and hoped somebody has a tip for me without me having to go to the local statistician on Monday. I assess 4 statements from 90 subjects. Each of the 4 statements receives one of three responses (say -1, 0, or 1). I can use Cramer's V or Spearman correlations to assess the correlation between each pair of statements, but I am looking for a measure of coherence across/among all 4 statements. To me, this seems to be intraclass correlation. So I was wondering whether I can apply it here (specifically, ICC(2,1) or ICC(3,1)) or whether I should use an alternative procedure given that my responses are ordinal. Daniel, The intraclass correlation is used if raters are all of the same ``class. That is, there is no logical way of distinguishing them. Examples include correlations between pairs of twins, correlations between raters. If the variables are logically distinguishable (e.g., different items on a test), then the more typical coefficient is based upon the inter-class correlation (e.g., a Pearson r) and a statistic such as alpha or omega might be used. The differences between the 3 types of ICCs are the type of generalization you want to make. Note that ICC3n is the same as coefficient alpha. ICC, alpha, and omega are all part of the psych package. Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html 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 __ 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] multiple error bars when NA present
At 1:38 AM -0500 7/24/09, Junqian Gordon Xu wrote: package: psych function: error.bars() R version: 2.9.1 OS: both linux and windows a-c(1,2,3,4,5) b-c(1,2,3,4,4) c-c(1,2,3,NA,5) data-data.frame(a,b,c) error.bars(data[,1:2],ylim=c(0,6)) looks fine however error.bars(data,ylim=c(0.6)) shows multiple error bars for each vector and the number of extra error bars equals to the number of vectors with NA value present. Is this a bug? Yes. It is a bug. Thanks for the report. Stay tuned. Bill Thanks Gordon -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r __ 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] Help With Fleiss Kappa
At 6:48 PM +1200 7/13/09, mehdi ebrahim wrote: Hi All, I am using fleiss kappa for inter rater agreement. Are there any know issues with Fleiss kappa calculation in R? Even when I supply mock data with total agreement among the raters I do not get a kappa value of 1. instead I am getting negative values. I am using the irr package version 0.70 Any help is much appreciated. Mehdi, Are you by any chance giving the function the agreement matrix rather than the raw data? The kappam.fliess function seems to want the ratings rather than the agreement matrix. Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] t-scores and correlation
Adrian and Jorge, Try either rcorr in the Hmisc package or corr.test in the psych package. They both will give you a matrix of correlations as well as the p values of the correlations. Bill At 4:38 PM -0400 7/10/09, Jorge Ivan Velez wrote: Hi Adrian, Using cor.test you need either two variables or a formula as stated in ?cor.test :-) Take a look at http://www.nabble.com/Re:-applying-cor.test-to-a-(m,-n)-matrix---SUMMARY-to17150239.html#a17150239 for different alternatives to do what you asked for. HTH, Jorge On Fri, Jul 10, 2009 at 4:25 PM, Adrian Johnson oriolebaltim...@gmail.comwrote: Thank you Jorge. I tried it, i have the following error. honestly I dont understand the error. could you help please. thank you. cor.test(t(longley),method='pearson') Error in cor.test.default(t(longley), method = pearson) : element 1 is empty; the part of the args list of 'length' being evaluated was: (y) On Fri, Jul 10, 2009 at 4:22 PM, Jorge Ivan Velezjorgeivanve...@gmail.com wrote: Dear Adrian, See ?cor.test. HTH, Jorge On Fri, Jul 10, 2009 at 4:13 PM, Adrian Johnson oriolebaltim...@gmail.com wrote: Hi I have a matrix with samples on columns and variables and their values on rows. I want to calculate correlation (pearson) between a variable and others in rows and obtain t-scores for the variables. how can i do it. thank you. Ad __ 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. [[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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] Best way to export values from a function?
Mark and Jason, At 7:23 PM -0700 7/8/09, Mark Knecht wrote: On Wed, Jul 8, 2009 at 5:55 PM, Mark Knechtmarkkne...@gmail.com wrote: On Wed, Jul 8, 2009 at 5:34 PM, Jason Rupertjasonkrup...@yahoo.com wrote: Maybe there is a great website out there or white paper that discusses this but again my Google skills (or lack there of) let me down. I would like to know the best way to export several doubles from a function, where the doubles are not an array. Here is a contrived function similar to my needs: multipleoutput-function(x) { squared-x^2 cubed-x^3 exponentioal-exp(x) factorialVal-factorial(x) } Thanks again for all your help. SNIP This version runs a bit better than my last and I find it a bit more readable, but there's a warning for whatever the first computation is inside the function that I'd like to understand. - Mark multipleoutput - function(x) { answer = c(Squ=0,Cub=0,Exp=0,Fac=0) answer$Squ=x^2 answer$Cub-x^3 answer$Exp-exp(x) answer$Fac-factorial(x) return(answer) } X = data.frame(Squared=0,Cubed=0,Exp=0,Fac=0) X mode(X) names(X) X[1,] - multipleoutput(2) X class(X) PRODUCES multipleoutput - function(x) { + answer = c(Squ=0,Cub=0,Exp=0,Fac=0) + answer$Squ=x^2 + answer$Cub-x^3 + answer$Exp-exp(x) + answer$Fac-factorial(x) + return(answer) + } X = data.frame(Squared=0,Cubed=0,Exp=0,Fac=0) X Squared Cubed Exp Fac 1 0 0 0 0 mode(X) [1] list names(X) [1] Squared Cubed Exp Fac X[1,] - multipleoutput(2) Warning message: In answer$Squ = x^2 : Coercing LHS to a list X Squared Cubed Exp Fac 1 4 8 7.389056 2 class(X) [1] data.frame ?list e.g., multipleoutput - function(x) { answer = list() answer$Squ=x^2 answer$Cub-x^3 answer$Exp-exp(x) answer$Fac-factorial(x) return(answer) } Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] estimate the reliability of a scale with dichotomous items
At 11:02 PM +0200 6/14/09, Martin Batholdy wrote: hi, How can I compute a reliability score of a scale consisting only of dichotomous items? RSiteSearch(cronbach's alpha) suggests the ltm, psych, psy, psycho, epicalc, packages (among others). There are a number of ways of estimating reliability, alpha is the most common (and perhaps overused). Other ways include MacDonald's omega_h and omega_t as well as the six estimates of Guttman. I tend to use the various functions found in psych, but then again, I am probably biased. Bill thanks for any help! __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] SEM/path question
Dear Erin, I agree with John that one should be careful about taking SEMs too seriously. For another good book on sem and path models, look at John Loehlin's book. Address = {Mahwah, N.J.}, Author = {Loehlin, John C}, Edition = {4th}, Publisher = {L. Erlbaum Associates}, Title = {Latent variable models: an introduction to factor, path, and structural equation analysis}, Year = {2004}} For baby sem examples, you might look at the vignette psych_for_sem in the psych package or some of the handouts at http://personality-project.org/revelle/syllabi/454.syllabus.pdf Bill At 4:11 PM -0400 5/29/09, John Fox wrote: Dear Erin, Although it's very old now, I like Duncan's Introduction to Structural Equation Modeling (Academic Press, 1975); for a more complete treatment, although it too is pretty old, Bollen, Structural Equations with Latent Variables (Wiley, 1989). I have notes and other materials from a short course on SEMs at http://socserv.mcmaster.ca/jfox/Courses/Brazil-2008/index.html. I feel compelled to add that one should be very carefully about taking SEMs seriously. Regards, John -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: May-29-09 3:28 PM To: R help Subject: [R] SEM/path question Dear R People: Could someone recommend a baby book on path analysis and SEM, please? Or if someone has an example that they use in the classroom setting, that would be very cool too. Thanks in advance, Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.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-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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] Hierarchical Diagram of Networks in sna or otherwise?
Jarrett, At 11:31 AM -0700 5/4/09, jebyrnes wrote: Nearly. The algorithm turns up slightly different graphs each time (and set.seed doesn't seem to make it consistent) and periodically chokes. But better than what I had. Hrm. I don't know much about the algorithm graphviz uses for dot. Do you have a reference on hand? If it's simple, I'd be willing to take a whack at it. Gábor Csárdi-2 wrote: Jarrett, the 'igraph' package has a layout called layout.reingold.tilford that is designed for trees, there is a slight chance that it is good enough for you. Best, Gabor On Wed, Apr 29, 2009 at 10:11 PM, jebyrnes byr...@msi.ucsb.edu wrote: I've been using sna to work with some networks, and am trying to visualize them easily. My networks are hierarchical (food webs). All of the layout engines I've tried with gplot don't seem to plot hierarchical networks, as one would using dot from graphviz. While I could do all of this by outputting to dotfiles and running it through graphviz, the graphics I get from R are much cleaner, and more easily integrated into my analyses. Is there any good way to diagram a hierarchical network in R, either with the sna library or otherwise? It strikes me that at least the Netindices package can calculate trophic levels. Could this be used for node placement? -Jarrett If you like the dot output from graphviz you can get that using Rgraphviz from bioconductor. Although somewhat difficult to install, once installed it works beautifully. Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] Re : PCA and automatic determination of the number of components
At 12:08 PM + 4/20/09, Jari Oksanen wrote: justin bem justin_bem at yahoo.fr writes: See ade4 or mva package. Justin BEM BP 1917 Yaoundé I guess the problem was not to find PCA (which is easy to find), but finding an automatic method of selecting (determining sounds like that selection would be correct in some objective sense) numbers of components to be retained. I thin neither ade4 nor mva give much support here (in particular the latter which does not exist any more). The usual place to look at is multivariate task view: http://cran.r-project.org/web/views/Multivariate.html Under the heading Projection methods and there under Principal components the taskview mentions packages nFactors and paran that help in selecting the number of components to retain. Are these Task Views really so invisible in R that people don't find them? Usually they are the first place to look at when you need something you don't have. In statistics, I mean. If they are invisible, could they be made more visible? Cheers, Jari Oksanen De : nikolay12 nikolay12 at gmail.com À : r-help at r-project.org Envoyé le : Lundi, 20 Avril 2009, 4h37mn 41s Objet : [R] PCA and automatic determination of the number of components Hi all, I have relatively small dataset on which I would like to perform a PCA. I am interested about a package that would also combine a method for determining the number of components (I know there are plenty of approaches to this problem). Any suggestions about a package/function? thanks, Nick ___ Henry Kaiser once commented that the Solving the number of factors problem is easy, I do it everyday before breakfast. But knowing the right solution is harder The psych package includes a number of ways to determine the number of components. Parallel analysis (comparing your solution to random ones), Minimum Absolute Partial correlations, Very Simple Structure are three of the better ways. Try functions fa.parallel and VSS. Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] Factor Analysis Output from R and SAS
13.696030772.62291629 0.61600.6160 21.073114480.07234039 0.17890.7949 31.000774090.83977061 0.16680.9617 40.161003480.12004232 0.02680.9885 50.040961160.01284515 0.00680.9953 60.02811601 0.00471. 3 factors will be retained by the NFACTOR criterion. Factor Pattern Factor1 Factor2 Factor3 v1 0.79880 0.54995-0.17614 v2 0.77036 0.56171-0.24862 v3 0.79475 -0.07685 0.54982 v4 0.75757 -0.08736 0.59785 v5 0.80878 -0.45610-0.33437 v6 0.1 -0.48331-0.36933 Variance Explained by Each Factor Factor1 Factor2 Factor3 3.6960308 1.0731145 1.0007741 Final Communality Estimates: Total = 5.769919 v1 v2 v3 v4 v5 v6 0.97154741 0.97078498 0.93983835 0.93897798 0.97394719 0.97482345 The FACTOR Procedure Rotation Method: Varimax Orthogonal Transformation Matrix 1 2 3 1 0.58233 0.57714 0.57254 2-0.64183 0.75864-0.11193 3-0.49895 -0.30229 0.81220 Rotated Factor Pattern Factor1 Factor2 Factor3 v1 0.20008 0.93148 0.25272 v2 0.21213 0.94590 0.17626 v3 0.23781 0.23418 0.91019 v4 0.19893 0.19023 0.92909 v5 0.93054 0.22185 0.24253 v6 0.94736 0.19384 0.19939 Variance Explained by Each Factor Factor1 Factor2 Factor3 1.9445607 1.9401828 1.8851759 Final Communality Estimates: Total = 5.769919 v1 v2 v3 v4 v5 v6 0.97154741 0.97078498 0.93983835 0.93897798 0.97394719 0.97482345 [[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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] pca vs. pfa: dimension reduction
Dear Sören, Mark, and Jon, At 12:51 PM -0700 3/25/09, Mark Difford wrote: Hi Sören, (1) Is there an easy example, which explains the differences between pca and pfa? (2) Which R procedure should I use to get what I want? There are a number of fundamental differences between PCA and FA (Factor Analysis), which unfortunately are quite widely ignored. FA is explicitly model-based, whereas PCA does not invoke an explicit model. FA is also designed to detect structure, whereas PCA focuses on variance, to put things simply. In more detail, the two methods attack the covariance matrix in different ways: in PCA the focus of decomposition is on the diagonal elements, whereas in FA the focus is on the off-diagonal elements. This is nicely put. Less concisely, see pages 139-149 of my (under development) book on psychometric theory using R (http://personality-project.org/r/book/Chapter6.pdf) In particular, on page 149: Although on the surface, the component model and factor model appear to very similar (compare Tables 6.6 and 6.7), they are in fact very different. One example of this is when an additional variable is added to the correlation matrix (Table 6.8). In this case, two additional variables are added to the correlation matrix. The factor pattern does not change, but the component pattern does. Why is this? Because the components are aimed at accounting for all of the variance of the matrix, adding new variables increases the amount of variance to be explained and changes the previous estimates. But the common part of the variables (that which is estimated by factors) is not sensitive to the presence (or absence) of other variables. Although a fundamental difference between the two models, this problem of the additional variable is most obvious when there are not very many variables and becomes less of an empirical problem as the number of variables increases. Take a look at Prof. Revelle's psych package (funtion omega c). Note also that factanal has a rotation = none option. Regards, Mark. soeren.vogel wrote: Can't make sense of calculated results and hope I'll find help here. I've collected answers from about 600 persons concerning three variables. I hypothesise those three variables to be components (or indicators) of one latent factor. In order to reduce data (vars), I had the following idea: Calculate the factor underlying these three vars. Use the loadings and the original var values to construct an new (artificial) var: (B1 * X1) + (B2 * X2) + (B3 * X3) = ArtVar (brackets for readability). Use ArtVar for further analysis of the data, that is, as predictor etc. For 3 variables, there is only one factor possible, so rotation is not a problem. (For 1 factor, there are 3 unknown factor loadings and 3 known correlations. The model is just identified. ) In my (I realise, elementary) psychological statistics readings I was taught to use pca for these problems. Referring to Venables Ripley (2002, chapter 11), I applied princomp to my vars. But the outcome shows 4 components -- which is obviously not what I want. Reading further I found factanal, which produces loadings on the one specified factor very fine. But since this is a contradiction to theoretical introductions in so many texts I'm completely confused whether I'm right with these calculations. If you want to think of what these variables have in common, use factor analysis, if you want to summarize them all most efficiently with one composite, use principal components. These are very different models. As Mark said, the difference is that FA accounts for the covariances (the off diagonal elements) which reflect what the variables have in common. PCS accounts for the entire matrix, which in a 3 x3 problem, is primarily the diagonal variances. Let me know if you need more information. Bill (1) Is there an easy example, which explains the differences between pca and pfa? (2) Which R procedure should I use to get what I want? Thank you for your help Sören Refs.: Venables, W. N., and Ripley, B. D. (2002). Modern applied statistics with S (4th edition). New York: Springer. __ 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. -- View this message in context: http://www.nabble.com/pca-vs.-pfa%3A-dimension-reduction-tp22707926p22709481.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. -- William Revelle http://personality
Re: [R] SEM model testing with identical goodness of fits (2)
tp-tp,e.tp,NA tr -tr,e.trv,NA the summary of both sem model gives identical fit indices, using same data set. is there some thing wrong with this mode specification? Thanks __ 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-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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] reliability, scale scores in the psych package
Ista, As you figured out, psych reverses items by subtracting from the maximimum + minimum possible for each item. (i.e., for items going from 1 to 4, it reverses items by subtracting from 5). If all of the items have the same potential range then you can just let it figure out the range by itself. If they differ in their ranges (some items are 0 - 1 items, some are 1-9 items, etc., then you need to give it the maximum and minimum vectors to use. The min and max are figured out from all the items used in an inventory, rather than just the items used in a particular scale. This makes particular sense when you are scoring multiple scales from the same inventory. In answer to your first question (what packages do I tend to use for scale construction?), the answer is that I tend to use the psych package for basic analysis, and then the sem package for structural equation analysis. Bill At 10:45 AM -0400 3/10/09, Ista Zahn wrote: snip Second question: I spent some time with the psych package trying to figure out how to use the score.items() function, and it's become clear to me that I don't understand what it's doing. I assumed that setting a key equal to -1 would result in the item being reverse scored, but I get weird results, as shown below. When I try to reverse score (by setting a value of -1 in the key), I get scale scores that don't add up (e.g., the mean score is reported as being larger than the maximum item score). How is the score.items() function intended to be used? Do I need to reverse score items before using score.items()? I did it again--it seems like I always figure out the answer just after I ask for help. The score.items() function needs to know the maximum of the scale in order to reverse score. For some reason, the maximum appears to be calculated from all the scores, not just scores that have a 1 or a -1 in the key. On a hunch I set the max argument to a vector of scale maxima, and it worked. I'm still interested in responses to question 1 though. Thanks again, Ista snip -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r __ 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] test two correlation coefficients against each other
Martin, See r.test in the psych package. This will probably do what you want to do. Bill At 1:29 AM +0100 3/11/09, Martin Batholdy wrote: hi, is there a function in R that calculates the probability that two correlation coefficients are from the same population? thanks! __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Use R for psychology http://personality-project.org/r __ 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] path analysis in R (standardized solution)
At 4:16 AM +0100 3/9/09, Martin Batholdy wrote: hi, this is my first time I use the sem package in R. I made a simple path analysis. Now I was wondering how to get the standardized solution. How can I get the standardized estimates of the path coefficients? ?std.coef __ 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. -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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] path analysis (misspecification?)
Martin, hi, I have following data and code; cov - c (1.670028 ,-1.197685 ,-2.931445,-1.197685,1.765646,3.883839,-2.931445,3.883839,12.050816) cov.matrix - matrix(cov, 3, 3, dimnames=list(c(y1,x1,x2), c(y1,x1,x2))) path.model - specify.model() x1 - y1, x1-y1 x2 - x1, x2-x1 x2 - x2, x2-x2 x1 - x1, x1-x1 y1 - y1, y1-y1 x2 - y1, x2-y1 summary(sem(path.model, cov.matrix, N = 422)) and I get following results; Model Chisquare = 12.524 Df = 1 Pr(Chisq) = 0.00040179 Chisquare (null model) = 812.69 Df = 3 Goodness-of-fit index = 0.98083 Adjusted goodness-of-fit index = 0.885 RMSEA index = 0.16545 90% CI: (0.09231, 0.25264) Bentler-Bonnett NFI = 0.98459 Tucker-Lewis NNFI = 0.9573 Bentler CFI = 0.98577 SRMR = 0.027022 BIC = 6.4789 Parameter Estimates Estimate Std Error z value Pr(|z|) x1-y1 -0.67833 0.033967 -19.970 0y1 --- x1 x2-x1 3.88384 0.293743 13.222 0x1 -- x2 x2-x2 12.05082 0.831569 14.492 0x2 -- x2 x1-x1 1.76565 0.121839 14.492 0x1 -- x1 y1-y1 0.85761 0.059124 14.505 0y1 -- y1 Iterations = 0 Now I wonder why the chi-square value is so bad and what Pr(Chisq) tells me. Can anyone help me on this? When I allow the path x2 - y1 I get of course a good fit, but the path coefficient of x2 - y1 is pretty low (-0.084653), so I thought I can restrict that one to zero. If you examine the residuals mod1 - sem(p.model,cov.matrix,N=422) residuals(mod1) You will see that you are completing ignoring the y1-x2 covariance. When you examine your covariance matrix as a correlation matrix, r.mat - cov2cor(cov.matrix) you will note that the x2-y1 relationship is very large (the correlation is -.65) Your original model was fully saturated and what you are reporting is actually what I label as p.model which is your full model without the last row. If you compare the fully saturated model with your mod1, you will find that the reason for the large chi square is due to not specifying the x2-y1 path. You might want to read some more on sem techniques. A good introduction is a text by John Loehlin. Bill -- William Revelle http://personality-project.org/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/ Attend ISSID/ARP:2009 http://issid.org/issid.2009/ __ 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.