Re: [R] pca analysis: extract rotated scores?
Hi, I am also doing PCA. Is the following right for extracting the scores? library(psych) pca-principal(data,nfactors=,rotate=varimax,scores=T) pca$loadings pca$score Best regards, He On Tue, Nov 30, 2010 at 10:22 AM, Liviu Andronic landronim...@gmail.com wrote: Dear all I'm unable to find an example of extracting the rotated scores of a principal components analysis. I can do this easily for the un-rotated version. data(mtcars) .PC - princomp(~am+carb+cyl+disp+drat+gear+hp+mpg, cor=TRUE, data=mtcars) unclass(loadings(.PC)) # component loadings summary(.PC) # proportions of variance mtcars$PC1 - .PC$scores[,1] # extract un-rotated scores of 1st principal component mtcars$PC2 - .PC$scores[,2] # extract un-rotated scores of 2nd principal component head(mtcars[, c('PC1', 'PC2')]) However, I no longer understand how to do so if I want to use ?principal in 'psych' and any of the GPArotation methods. For example, require(psych) r - cor(mtcars[,c(am,carb,cyl,disp,drat,gear,hp,mpg)]) pca - principal(r, nfactors = 8, residuals = T, rotate=none) # or 'varimax' or any other GPArotation supported rotation pca I've turned the 'pca' object and ?principal help page upside down and I still cannot find anything that would resemble a 'scores' value. I'm pretty sure it's one matrix computation away, but I cannot find which one. Ideas? Thank you Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ 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] Evaluation of survival analysis
-- Forwarded message -- From: He Zhang hzsha...@googlemail.com Date: Tue, Nov 30, 2010 at 11:26 AM Subject: Re: [R] Evaluation of survival analysis To: Mike Marchywka marchy...@hotmail.com Cc: r-help@r-project.org On Tue, Nov 30, 2010 at 1:18 AM, Mike Marchywka marchy...@hotmail.comwrote: Hello Mike, Thank you very much for your reply and help. May i describe the analysis more clearly? My data is ecology data and my task is to 1) relate the 8 candidate (life history) varaibles with the lifespan of each subject and 2) use the known variables to predict lifespan. For the 1st task, i used Cox regression coxph() to do uni-variate analysis first. However, the most variables are correlated with each. For involving more variables, principle component analysis is applied. After PAC principal(), I chose three vairalbes according to the results (instead of the derived principle components since the interpretation of the original variables is easier) . For the 2nd task, i wanted to use the chosen variables to predict the lifespan. predict(survreg()) can get the values. I attached parts of the results which are the residuals plot and predcited values vs. predictors derived from both Cox regression and parametric survival. My problem: 1) not sure if the methods are correct for the tasks since the residuals plots are not totally randomly and the predicted hazard is less than 0. 2) i dont know how to explain the fitness of the model. Any suggestion about the methods or results will be really appreciate. Thank you again. Best wishes, He Date: Mon, 29 Nov 2010 09:26:07 +0100 From: hzsha...@googlemail.com To: r-help@r-project.org Subject: [R] Evaluation of survival analysis Dear all, May I ask is there any functions in R to evaluate the fitness of coxph and survreg in survival analysis, please? For example, the results from Cox regression and Parametric survival analysis are shown below. Which method is prefered and how to see that / how to compare the methods? I don't know if anyone answered but personally I like to look at pictures and relate to causality. Even the lecture slides I've seen ultimately suggest looking at scatter plots of various residuals for patterns. If known or suspected dynamics better fit with one model or the other that would likely be of interest. Generally if you pick enough parameters retrospectively you can probably get about what ever answer you want from a quantitative comparison. 1. coxph(formula = y ~ pspline(x1, df = 2)) coef se(coef) se2 Chisq DF p pspline(x1, df = 2), line 0.0522 0.00867 0.00866 36.23 1.00 1.8e-09 pspline(x1, df = 2), nonl 3.27 1.04 7.5e-02 Iterations: 4 outer, 13 Newton-Raphson Theta= 0.91 Degrees of freedom for terms= 2 Likelihood ratio test=34.6 on 2.04 df, p=3.24e-08 2. survreg(formula = y ~ pspline(x1, df = 2)) coef se(coef) se2 Chisq DF p (Intercept) 2.8199 0.15980 0.09933 311.37 1.0 0.0e+00 pspline(x1, df = 2), line -0.0193 0.00248 0.00248 60.35 1.0 8.0e-15 pspline(x1, df = 2), nonl 1.43 1.1 2.6e-01 Scale= 0.304 Iterations: 6 outer, 20 Newton-Raphson Theta= 0.991 Degrees of freedom for terms= 0.4 2.1 1.0 Likelihood ratio test=48.2 on 1.5 df, p=1.18e-11 I really appreciate for your help. Thank you very much in advance. Best wishes, He __ 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] Evaluation of survival analysis
On Tue, Nov 30, 2010 at 1:18 AM, Mike Marchywka marchy...@hotmail.comwrote: Hello Mike, Thank you very much for your reply and help. May i describe the analysis more clearly? My data is ecology data and my task is to 1) relate the 8 candidate (life history) varaibles with the lifespan of each subject and 2) use the known variables to predict lifespan. For the 1st task, i used Cox regression coxph() to do uni-variate analysis first. However, the most variables are correlated with each. For involving more variables, principle component analysis is applied. After PAC principal(), I chose three vairalbes according to the results (instead of the derived principle components since the interpretation of the original variables is easier) . For the 2nd task, i wanted to use the chosen variables to predict the lifespan. predict(survreg()) can get the values. I attached parts of the results which are the residuals plot and predcited values vs. predictors derived from both Cox regression and parametric survival. My problem: 1) not sure if the methods are correct for the tasks since the residuals plots are not totally randomly and the predicted hazard is less than 0. 2) i dont know how to explain the fitness of the model. Any suggestion about the methods or results will be really appreciate. Thank you again. Best wishes, He Date: Mon, 29 Nov 2010 09:26:07 +0100 From: hzsha...@googlemail.com To: r-help@r-project.org Subject: [R] Evaluation of survival analysis Dear all, May I ask is there any functions in R to evaluate the fitness of coxph and survreg in survival analysis, please? For example, the results from Cox regression and Parametric survival analysis are shown below. Which method is prefered and how to see that / how to compare the methods? I don't know if anyone answered but personally I like to look at pictures and relate to causality. Even the lecture slides I've seen ultimately suggest looking at scatter plots of various residuals for patterns. If known or suspected dynamics better fit with one model or the other that would likely be of interest. Generally if you pick enough parameters retrospectively you can probably get about what ever answer you want from a quantitative comparison. 1. coxph(formula = y ~ pspline(x1, df = 2)) coef se(coef) se2 Chisq DF p pspline(x1, df = 2), line 0.0522 0.00867 0.00866 36.23 1.00 1.8e-09 pspline(x1, df = 2), nonl 3.27 1.04 7.5e-02 Iterations: 4 outer, 13 Newton-Raphson Theta= 0.91 Degrees of freedom for terms= 2 Likelihood ratio test=34.6 on 2.04 df, p=3.24e-08 2. survreg(formula = y ~ pspline(x1, df = 2)) coef se(coef) se2 Chisq DF p (Intercept) 2.8199 0.15980 0.09933 311.37 1.0 0.0e+00 pspline(x1, df = 2), line -0.0193 0.00248 0.00248 60.35 1.0 8.0e-15 pspline(x1, df = 2), nonl 1.43 1.1 2.6e-01 Scale= 0.304 Iterations: 6 outer, 20 Newton-Raphson Theta= 0.991 Degrees of freedom for terms= 0.4 2.1 1.0 Likelihood ratio test=48.2 on 1.5 df, p=1.18e-11 I really appreciate for your help. Thank you very much in advance. Best wishes, He __ 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] Evaluation of survival analysis
Dear all, May I ask is there any functions in R to evaluate the fitness of coxph and survreg in survival analysis, please? For example, the results from Cox regression and Parametric survival analysis are shown below. Which method is prefered and how to see that / how to compare the methods? 1. coxph(formula = y ~ pspline(x1, df = 2)) coef se(coef) se2 Chisq DF p pspline(x1, df = 2), line 0.0522 0.00867 0.00866 36.23 1.00 1.8e-09 pspline(x1, df = 2), nonl3.27 1.04 7.5e-02 Iterations: 4 outer, 13 Newton-Raphson Theta= 0.91 Degrees of freedom for terms= 2 Likelihood ratio test=34.6 on 2.04 df, p=3.24e-08 2. survreg(formula = y ~ pspline(x1, df = 2)) coefse(coef)se2 ChisqDF p (Intercept)2.8199 0.15980 0.09933 311.37 1.0 0.0e+00 pspline(x1, df = 2), line -0.0193 0.00248 0.00248 60.35 1.0 8.0e-15 pspline(x1, df = 2), nonl 1.43 1.1 2.6e-01 Scale= 0.304 Iterations: 6 outer, 20 Newton-Raphson Theta= 0.991 Degrees of freedom for terms= 0.4 2.1 1.0 Likelihood ratio test=48.2 on 1.5 df, p=1.18e-11 I really appreciate for your help. Thank you very much in advance. Best wishes, He [[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.