[R] Path analysis
Hi there, As I'm approaching path analysis I was wondering which packages may suite a path analysis for my data. My data are on interaction of soil biotic and abiotic factor, like microbial biomass carbon, soil carbon, water content, temperature etc. Thanks in advance, Best regards. Alberto Alberto Canarini PhD Student l Faculty of Agriculture and Environment THE UNIVERSITY OF SYDNEY Shared room l CCWF l Camden Campus l NSW 2570 P 02 935 11892 [[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.
Re: [R] Path analysis
Dear Alberto, There are several R packages available on CRAN for structural equation modeling: sem, lavaan, and OpenMx come immediately to mind. If your model is recursive with only observed variables, then you could just use lm(). If your model is nonrecursive with only observed variables, then you could also use the systemfit package. I hope this helps, John John Fox, Professor McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Tue, 26 May 2015 05:43:47 + Alberto Canarini alberto.canar...@sydney.edu.au wrote: Hi there, As I'm approaching path analysis I was wondering which packages may suite a path analysis for my data. My data are on interaction of soil biotic and abiotic factor, like microbial biomass carbon, soil carbon, water content, temperature etc. Thanks in advance, Best regards. Alberto Alberto Canarini PhD Student l Faculty of Agriculture and Environment THE UNIVERSITY OF SYDNEY Shared room l CCWF l Camden Campus l NSW 2570 P 02 935 11892 [[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. __ 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] Path analysis
Given that your problem primarily focuses on a biological context you probably would have better luck with bioconductor (www.bioconductor.org). Regards, Charles On Tue, May 26, 2015 at 12:43 AM, Alberto Canarini alberto.canar...@sydney.edu.au wrote: Hi there, As I'm approaching path analysis I was wondering which packages may suite a path analysis for my data. My data are on interaction of soil biotic and abiotic factor, like microbial biomass carbon, soil carbon, water content, temperature etc. Thanks in advance, Best regards. Alberto Alberto Canarini PhD Student l Faculty of Agriculture and Environment THE UNIVERSITY OF SYDNEY Shared room l CCWF l Camden Campus l NSW 2570 P 02 935 11892 [[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. [[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.
Re: [R] Path Analysis
Dear John, Thanks for your help. I run the path analysis but the model does not fit the data. I am in doubt if this reflects the model construction et al. (too many variables or more needed, more paths or change in direction of paths, sample size, etc) or it could be that there is an error-variance I have all observed data (fully recursive model), two exogenous variables (with no variance or covariance parameters), four exogenous variables, and for the final sem() model I used data argument instead of a moment matrix with the covariance symmetric matrix. What would you suggest to be the best way to investigate this in R? Here attached the script and results: library(sem) model.xdata-specifyEquations() y1=xy21*x2 y2=xy12*x1 + yy12*y1 y3=yy23*y2 y4=yy24*y2+yy34*y3 model.xdata.sem - sem(model.xdata, data=xdata, fixed.x=c(x1, x2) ) summary(model.xdata.sem,fit.indices=c(CFI,NFI, GFI, RMSEA, AGFI, NNFI, SRMR)) Model Chisquare = 41.03029 Df = 8 Pr(Chisq) = 2.057595e-06 Goodness-of-fit index = 0.8604332 Adjusted goodness-of-fit index = 0.6336373 RMSEA index = 0.2330797 90% CI: (0.1654494, 0.3060134) Bentler-Bonett NFI = 0.4290901 Tucker-Lewis NNFI = -0.08903999 Bentler CFI = 0.4191787 SRMR = 0.1472905 Normalized Residuals Min. 1st Qu. Median Mean 3rd Qu. Max. -3.91600 -0.60120 0.0 -0.09444 0.13940 2.71400 R-square for Endogenous Variables y1 y2 y3 y4 0.0009 0.1890 0.0019 0.1558 Parameter Estimates Estimate Std Errorz value Pr(|z|) xy210.017817121 0.066762981 0.26687127 7.895683e-01 y1 --- x2 xy12 -0.030928721 0.007447431 -4.15293810 3.282335e-05 y2 --- x1 yy120.311216816 0.475353649 0.65470585 5.126572e-01 y2 --- y1 yy23 -0.077701789 0.203130269 -0.38252196 7.020742e-01 y3 --- y2 yy240.002539283 0.031323241 0.08106706 9.353886e-01 y4 --- y2 yy340.066168523 0.017671263 3.74441396 1.808153e-04 y4 --- y3 V[y1] 1.945406949 0.315586680 6.16441400 7.074463e-10 y1 -- y1 V[y2] 33.438573159 5.424452858 6.16441400 7.074463e-10 y2 -- y2 V[y3] 129.295382082 20.974480627 6.16441400 7.074463e-10 y3 -- y3 V[y4] 3.068539923 0.497782907 6.16441400 7.074463e-10 y4 -- y4 On 2 November 2013 19:48, John Fox j...@mcmaster.ca wrote: Dear Sarah, It's generally a good idea to include a reproducible example if you want to get help with a problem, but in this case it's a safe bet that the problem is that the model you specified has no variance or covariance parameters for the variables x1 and x2, which, I assume, you mean to be exogenous. The easiest way to include these variances and covariance in the model is to specify the argument fixed.x=c(x1, x2) in the call to sem(). In addition: (1) Your model is fully recursive (guessing that all the x's and y's are observed variables), and so it amounts to four OLS regressions. You could just use lm() to fit the model. (2) It's generally easier in the sem package to use specifyEquations() than specifyModel() for model specification. (3) If you have the original data set, as you do, it's generally preferable to use the data argument to sem() than to pass it the covariance matrix for the observed variables. I hope that this helps, John John Fox McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Sat, 2 Nov 2013 11:02:31 +0100 Sarah Rogers rogerssara...@gmail.com wrote: Hello, I have just started to work on a path analysis (see attached image for the diagram), but I have encountered an error message. This is the code I have used: cov_matrix-var(xdata) library(sem) model.xdata-specifyModel() x1 - y2, xy12, NA x2 - y1, xy21, NA y1 - y2, yy12, NA y2 - y3, yy23, NA y2 - y4, yy24, NA y3 - y4, yy34, NA y2 - y2, y2error, NA y1 - y1, y1error, NA y3 - y3, y3error, NA y4 - y4, y4error, NA model.xdata.sem - sem(model.xdata, cov_matrix, nrow(xdata)) and the error message is: Error in csem(model = model.description, start, opt.flag = 1, typsize = typsize, : The matrix is non-invertable. I fear to have a problem in the data. I would be very grateful if you could help me to solve this problem and proceed with my analyses. thank you in advance for your help! Sarah [[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,
Re: [R] Path Analysis
Dear Sarah, As you know, our discussion continued off-list, and I'm glad that you were able to get the software to work. I'll address your question briefly, but what I have to say probably isn't what you want to hear: Most fundamentally, the information you've provided is entirely without content. That is, variable names like x1 and y1 convey no information about the substance of the data. It's therefore impossible to know whether the model that you specified is sensible. I think that you'd do much better to seek competent statistical help locally than to ask questions on an email list devoted to statistical software. That said, you've specified a very restrictive model for the data. You could add 8 paths to the model and still have a fully recursive model. For example, your model specifies that x2 can only influence y4 indirectly through y1. If you've carefully specified the model and believe, for example, that the missing paths are implausible, that x1 and x2 are really exogenous, and that all of the disturbances are uncorrelated, then the correct conclusion is that your model is wrong. You could try adding the missing paths to the model, but if you're willing to do this that would suggest that you didn't think carefully enough about the specification in the first place. In my opinion, structural-equation modeling shouldn't be regarded as an exploratory method. Of course, in a very large sample, an overidentified model that's trivially wrong can be rejected when tested as a hypothesis. I don't know how large your sample is, but the various fit indices are not encouraging. Your model isn't just trivially wrong. Moreover, the R^2s for the endogenous variable are very small -- two are effectively 0. I can't judge whether your model makes any sense, but it's my impression that most structural equation models don't. People often think that SEMs are magic wands that can be waved over observational data to draw causal inferences, even when the assumptions underlying the model, such as exogeneity, are implausible, and without attending to aspects of the model, such as potential nonlinearity, that should be part of careful regression modeling. My two cents, John -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Sarah Rogers Sent: Tuesday, November 05, 2013 8:45 AM To: r-help@r-project.org Cc: John Fox Subject: Re: [R] Path Analysis Dear John, Thanks for your help. I run the path analysis but the model does not fit the data. I am in doubt if this reflects the model construction et al. (too many variables or more needed, more paths or change in direction of paths, sample size, etc) or it could be that there is an error-variance I have all observed data (fully recursive model), two exogenous variables (with no variance or covariance parameters), four exogenous variables, and for the final sem() model I used data argument instead of a moment matrix with the covariance symmetric matrix. What would you suggest to be the best way to investigate this in R? Here attached the script and results: library(sem) model.xdata-specifyEquations() y1=xy21*x2 y2=xy12*x1 + yy12*y1 y3=yy23*y2 y4=yy24*y2+yy34*y3 model.xdata.sem - sem(model.xdata, data=xdata, fixed.x=c(x1, x2) ) summary(model.xdata.sem,fit.indices=c(CFI,NFI, GFI, RMSEA, AGFI, NNFI, SRMR)) Model Chisquare = 41.03029 Df = 8 Pr(Chisq) = 2.057595e-06 Goodness-of-fit index = 0.8604332 Adjusted goodness-of-fit index = 0.6336373 RMSEA index = 0.2330797 90% CI: (0.1654494, 0.3060134) Bentler-Bonett NFI = 0.4290901 Tucker-Lewis NNFI = -0.08903999 Bentler CFI = 0.4191787 SRMR = 0.1472905 Normalized Residuals Min. 1st Qu. Median Mean 3rd Qu. Max. -3.91600 -0.60120 0.0 -0.09444 0.13940 2.71400 R-square for Endogenous Variables y1 y2 y3 y4 0.0009 0.1890 0.0019 0.1558 Parameter Estimates Estimate Std Errorz value Pr(|z|) xy210.017817121 0.066762981 0.26687127 7.895683e-01 y1 --- x2 xy12 -0.030928721 0.007447431 -4.15293810 3.282335e-05 y2 --- x1 yy120.311216816 0.475353649 0.65470585 5.126572e-01 y2 --- y1 yy23 -0.077701789 0.203130269 -0.38252196 7.020742e-01 y3 --- y2 yy240.002539283 0.031323241 0.08106706 9.353886e-01 y4 --- y2 yy340.066168523 0.017671263 3.74441396 1.808153e-04 y4 --- y3 V[y1] 1.945406949 0.315586680 6.16441400 7.074463e-10 y1 -- y1 V[y2] 33.438573159 5.424452858 6.16441400 7.074463e-10 y2 -- y2 V[y3] 129.295382082 20.974480627 6.16441400 7.074463e-10 y3 -- y3 V[y4] 3.068539923 0.497782907 6.16441400 7.074463e-10 y4 -- y4 On 2 November 2013 19:48, John Fox j...@mcmaster.ca wrote: Dear Sarah, It's generally a good idea to include a reproducible example if you want to get help with a problem, but in this case it's a safe bet that the problem is that the model you specified has
[R] Path Analysis
Hello, I have just started to work on a path analysis (see attached image for the diagram), but I have encountered an error message. This is the code I have used: cov_matrix-var(xdata) library(sem) model.xdata-specifyModel() x1 - y2, xy12, NA x2 - y1, xy21, NA y1 - y2, yy12, NA y2 - y3, yy23, NA y2 - y4, yy24, NA y3 - y4, yy34, NA y2 - y2, y2error, NA y1 - y1, y1error, NA y3 - y3, y3error, NA y4 - y4, y4error, NA model.xdata.sem - sem(model.xdata, cov_matrix, nrow(xdata)) and the error message is: Error in csem(model = model.description, start, opt.flag = 1, typsize = typsize, : The matrix is non-invertable. I fear to have a problem in the data. I would be very grateful if you could help me to solve this problem and proceed with my analyses. thank you in advance for your help! Sarah [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Path Analysis
Dear Sarah, It's generally a good idea to include a reproducible example if you want to get help with a problem, but in this case it's a safe bet that the problem is that the model you specified has no variance or covariance parameters for the variables x1 and x2, which, I assume, you mean to be exogenous. The easiest way to include these variances and covariance in the model is to specify the argument fixed.x=c(x1, x2) in the call to sem(). In addition: (1) Your model is fully recursive (guessing that all the x's and y's are observed variables), and so it amounts to four OLS regressions. You could just use lm() to fit the model. (2) It's generally easier in the sem package to use specifyEquations() than specifyModel() for model specification. (3) If you have the original data set, as you do, it's generally preferable to use the data argument to sem() than to pass it the covariance matrix for the observed variables. I hope that this helps, John John Fox McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Sat, 2 Nov 2013 11:02:31 +0100 Sarah Rogers rogerssara...@gmail.com wrote: Hello, I have just started to work on a path analysis (see attached image for the diagram), but I have encountered an error message. This is the code I have used: cov_matrix-var(xdata) library(sem) model.xdata-specifyModel() x1 - y2, xy12, NA x2 - y1, xy21, NA y1 - y2, yy12, NA y2 - y3, yy23, NA y2 - y4, yy24, NA y3 - y4, yy34, NA y2 - y2, y2error, NA y1 - y1, y1error, NA y3 - y3, y3error, NA y4 - y4, y4error, NA model.xdata.sem - sem(model.xdata, cov_matrix, nrow(xdata)) and the error message is: Error in csem(model = model.description, start, opt.flag = 1, typsize = typsize, : The matrix is non-invertable. I fear to have a problem in the data. I would be very grateful if you could help me to solve this problem and proceed with my analyses. thank you in advance for your help! Sarah [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] path analysis
What's the function of 'path analysis ' to do it with R? Please help me.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.
Re: [R] path analysis
First, hello, Second, http://r.789695.n4.nabble.com/path-analysis-td2528558.html#a2530207 Last, Regards Le 26/12/2012 04:11, Ali Mahmoudi a écrit : What's the function of 'path analysis ' to do it with R? Please help me.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. __ 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] path analysis help
Hi there, I searched R-help list with path analysis as keyword, and learn that sem package can do it. However, I don't figure out a way to construct the model for the path diagram as Fig. 1. in Huang et al. (2002)[1]. I try the following code: huang.cor - readMoments(diag=FALSE, names=c('x1', 'x2', 'x3', 'y')) 0.76 0.91 0.72 0.94 0.77 0.83 huang.mod - specifyModel() x1 - y, p1 x2 - y, p2 x3 - y, p3 x1 - x2, p12 x2 - x1, p21 x2 - x3, p23 x3 - x2, p32 x1 - x3, p13 x3 - x1, p31 huang.sem - sem(huang.mod, huang.cor, 100)# 100 is arbitarious. It give the error message: Error in sem.default(ram, S = S, N = N, raw = raw, data = data, param.names = pars, : The model has negative degrees of freedom = -3 I don't know why. I hope to get direct effect, indirect effect and total effects for every variable. However, I don't figure out how to do with sem package. It there any other package that can do it? Any suggestion or hint will be greatly appreciated. Regards, Jinsong [1] Huang, B., Thornhill, N., Shah, S. and Shook, D. (2002). Path analysis for process troubleshooting. Proceedings of Advanced Control of Industrial Processes, Kumamoto, Japan, 10–12 June, 149–154. url: http://eprints.ucl.ac.uk/494/1/HuangEtAl_AdConIP_2002.pdf __ 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 help
Dear Jinsong, This model is grossly underidentified because there are no exogenous variables in it. Your inability to estimate the model isn't a software issue. Best, John --- John Fox Senator McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jinsong Zhao Sent: Thursday, August 30, 2012 10:47 AM To: r-help@r-project.org Subject: [R] path analysis help Hi there, I searched R-help list with path analysis as keyword, and learn that sem package can do it. However, I don't figure out a way to construct the model for the path diagram as Fig. 1. in Huang et al. (2002)[1]. I try the following code: huang.cor - readMoments(diag=FALSE, names=c('x1', 'x2', 'x3', 'y')) 0.76 0.91 0.72 0.94 0.77 0.83 huang.mod - specifyModel() x1 - y, p1 x2 - y, p2 x3 - y, p3 x1 - x2, p12 x2 - x1, p21 x2 - x3, p23 x3 - x2, p32 x1 - x3, p13 x3 - x1, p31 huang.sem - sem(huang.mod, huang.cor, 100)# 100 is arbitarious. It give the error message: Error in sem.default(ram, S = S, N = N, raw = raw, data = data, param.names = pars, : The model has negative degrees of freedom = -3 I don't know why. I hope to get direct effect, indirect effect and total effects for every variable. However, I don't figure out how to do with sem package. It there any other package that can do it? Any suggestion or hint will be greatly appreciated. Regards, Jinsong [1] Huang, B., Thornhill, N., Shah, S. and Shook, D. (2002). Path analysis for process troubleshooting. Proceedings of Advanced Control of Industrial Processes, Kumamoto, Japan, 10-12 June, 149-154. url: http://eprints.ucl.ac.uk/494/1/HuangEtAl_AdConIP_2002.pdf __ 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] path analysis and diagram (structural model)
Hi R- USER, I have been struggling to compute path analysis in R. I installed package sem and I tried to run the analysis but could not get a diagram. I have very big data set, here I just copied a sample of my data and I wanted to see how I can do the path analysis and get the patch diagram (with r2 in each path). I have two tables; 1: num. of species - which is the depended variable and 2. env is the independent(predictors) variable. I was trying to do multiple regression (num. of species vs env) and trying to see the path diagram (structural model). But I could not do it. would you help me on how I can perform the analysis and show in diagram of the model? dput(env) structure(list(preci = c(45.145, 38.501, 32.631, 38.392, 44.807, 45.774, 46.917, 44.384), wind = c(90L, 113L, 127L, 63L, 54L, 43L, 31L, 38L), radiation = c(11.805, 18.31, 19.381, 13.154, 9.752, 7.075, 5.558, 7.616), temp = c(12L, 15L, 21L, 20L, 14L, 18L, 21L, 18L)), .Names = c(preci, wind, radiation, temp ), class = data.frame, row.names = c(NA, -8L)) dput(num.of.species) structure(list(S = c(4L, 7L, 9L, 10L, 10L, 8L, 8L, 1L)), .Names = S, class = data.frame, row.names = c(NA, -8L)) Sincerely, Kristi [[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] Path analysis with logistic regression
Dear all, I would like to make a path analysis after retrieving relevant variables (continuous or binary) after logistic regression. So I try to model the dependent variable (0/1) based on the significant predictors using path analysis Could you tell me if there is a suitable package in R to do this? Any help would be appreciated Regards -- Mohamed Lajnef,IE INSERM U955 eq 15# Pôle de Psychiatrie# Hôpital CHENEVIER # 40, rue Mesly # 94010 CRETEIL Cedex FRANCE # mohamed.laj...@inserm.fr # tel : 01 49 81 31 31 (poste 18467) # Sec : 01 49 81 32 90 # fax : 01 49 81 30 99 # [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] path analysis
There are three paths to path analysis in R: the SEM package; the LAVAAN package; and the OpenMx approach. The first two are R programs. The last accesses the program OpenMx. Guy rotem rottem...@gmail.com Sent by: r-help-boun...@r-project.org 09/06/2010 10:37 AM To r-help@r-project.org cc Subject [R] path analysis Hi. which package i need to install to be able to run Path analysis using r? many thanks, Guy -- Guy Rotem Department of Life Sciences The Spatial Ecology Lab Ben Gurion University of the Negev P.O.B. 653 Beer-Sheva 84105 ISRAEL +972-52-3354485 (mobile) +972-8-6461350 (lab) [[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.
Re: [R] path analysis
Guy, For a partial least squares approach look at packages plspm and pathmox. Also look at sem.additions. Regards, Mark. -- View this message in context: http://r.789695.n4.nabble.com/path-analysis-tp2528558p2530207.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] path analysis
Hi. which package i need to install to be able to run Path analysis using r? many thanks, Guy -- Guy Rotem Department of Life Sciences The Spatial Ecology Lab Ben Gurion University of the Negev P.O.B. 653 Beer-Sheva 84105 ISRAEL +972-52-3354485 (mobile) +972-8-6461350 (lab) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] path analysis
There are lots of options for path analysis in R. If you go to http://www.rseek.org and type path analysis into the search box, you will get lots of information on functions/packages, and more general info as well. Beyond that, we'd need more specifics about your task. Sarah On Mon, Sep 6, 2010 at 10:37 AM, Guy rotem rottem...@gmail.com wrote: Hi. which package i need to install to be able to run Path analysis using r? many thanks, Guy -- 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.
[R] Path Analysis
Hello list, I'm trying to make sure that I'm performing a path analysis correctly using the sem package. the figure at http://flame.cs.dal.ca/~sstewart/regressDiag.png has a detailing of the model. The challenge I'm having is that reuse is an indicator (0/1) variable. Here's the code I'm using: corr = hetcor(dat[,c('intent','exposure','benefit','norms','childBarrier','parentBarrier','knowBenefit','recuse')],use=pairwise.complete.obs)$correlations modMat = matrix(c( 'exposure - intent', 'gam11',NA, 'benefit - intent', 'gam12',NA, 'norms - intent', 'gam13',NA, 'childBarrier - intent', 'gam14',NA, 'parentBarrier - intent', 'gam15',NA, 'knowBenefit - intent', 'gam16',NA, 'intent-intent','psi11',NA, 'intent-recuse','gam21',NA, 'recuse-recuse','psi22',NA), ncol=3,byrow=T) model4 = sem(modMat,corr,N=1520,fixed.x=c('exposure','benefit','norms','childBarrier','parentBarrier','knowBenefit')) Is this correctly modeling my diagram? I'm not sure if a) I'm dealing with the categorical variable correctly, or b) whether fixed.x is accurately modeling the correlations for me. Any help would be appreciated. I'm also looking into creating a plot function within R (similar to the path.diagram function, but using R plots). If I get something useful I'll try and post it back __ 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
Dear sstewart, The model appears to reflect the path diagram, assuming that you intend to allow the exogenous variables to be correlated and want the errors to be uncorrelated. This is one way to model the binary variable reuse. An alternative would be to fit the equation for intent by least-squares regression (assuming that the relationships are linear, etc.), and the equation of reuse by, e.g., logistic regression (again assuming that the model is correctly specified). If you're right that the effects of the exogenous variables are entirely mediated by intent, then if you put these variables in the equation for reuse, their coefficients should be small. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of R Help Sent: May-24-10 11:18 AM To: r-help Subject: [R] Path Analysis Hello list, I'm trying to make sure that I'm performing a path analysis correctly using the sem package. the figure at http://flame.cs.dal.ca/~sstewart/regressDiag.png has a detailing of the model. The challenge I'm having is that reuse is an indicator (0/1) variable. Here's the code I'm using: corr = hetcor(dat[,c('intent','exposure','benefit','norms','childBarrier','parentBa r rier','knowBenefit','recuse')],use=pairwise.complete.obs)$correlations modMat = matrix(c( 'exposure - intent', 'gam11',NA, 'benefit - intent', 'gam12',NA, 'norms - intent', 'gam13',NA, 'childBarrier - intent', 'gam14',NA, 'parentBarrier - intent', 'gam15',NA, 'knowBenefit - intent', 'gam16',NA, 'intent-intent','psi11',NA, 'intent-recuse','gam21',NA, 'recuse-recuse','psi22',NA), ncol=3,byrow=T) model4 = sem(modMat,corr,N=1520,fixed.x=c('exposure','benefit','norms','childBarrier' , 'parentBarrier','knowBenefit')) Is this correctly modeling my diagram? I'm not sure if a) I'm dealing with the categorical variable correctly, or b) whether fixed.x is accurately modeling the correlations for me. Any help would be appreciated. I'm also looking into creating a plot function within R (similar to the path.diagram function, but using R plots). If I get something useful I'll try and post it back __ 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] Path Analysis
That's an interesting idea, I got the same impression from your SEM appendix to Companion to applied regression in the paragraph just before Section 3. So I could get the same results if I built the following two models: mod1 = lm(intent~exposure+benefit+norms+childBarrier+parentBarrier+knowBenefit,data=dat) mod2 = glm(recuse~intent+norms+exposure+childBarrier+parentBarrier,data=dat,family=binomial(link=logit)) And in the second model only the intent should have a significant coefficient? When I run those models I get a number of significant findings in the mod2. Does that mean that I have mis-specified my model? If so (and I think I have), can I postulate that there is a link between each significant coefficient? Thanks so much for your input, Sam Stewart summary(mod2) Call: glm(formula = recuse ~ intent + norms + exposure + childBarrier + parentBarrier, family = binomial(link = logit), data = dat) Deviance Residuals: Min 1Q Median 3Q Max -2.2784 -0.9018 0.5899 0.7686 1.9314 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) -2.512690.50359 -4.990 6.05e-07 *** intent 0.595740.08345 7.139 9.39e-13 *** norms 0.238220.02991 7.964 1.67e-15 *** exposure 0.125220.08613 1.454 0.145981 childBarrier -0.312960.08693 -3.600 0.000318 *** parentBarrier -0.234000.08676 -2.697 0.006995 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1803.0 on 1479 degrees of freedom Residual deviance: 1567.8 on 1474 degrees of freedom (40 observations deleted due to missingness) AIC: 1579.8 Number of Fisher Scoring iterations: 4 On Mon, May 24, 2010 at 1:17 PM, John Fox j...@mcmaster.ca wrote: Dear sstewart, The model appears to reflect the path diagram, assuming that you intend to allow the exogenous variables to be correlated and want the errors to be uncorrelated. This is one way to model the binary variable reuse. An alternative would be to fit the equation for intent by least-squares regression (assuming that the relationships are linear, etc.), and the equation of reuse by, e.g., logistic regression (again assuming that the model is correctly specified). If you're right that the effects of the exogenous variables are entirely mediated by intent, then if you put these variables in the equation for reuse, their coefficients should be small. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of R Help Sent: May-24-10 11:18 AM To: r-help Subject: [R] Path Analysis Hello list, I'm trying to make sure that I'm performing a path analysis correctly using the sem package. the figure at http://flame.cs.dal.ca/~sstewart/regressDiag.png has a detailing of the model. The challenge I'm having is that reuse is an indicator (0/1) variable. Here's the code I'm using: corr = hetcor(dat[,c('intent','exposure','benefit','norms','childBarrier','parentBa r rier','knowBenefit','recuse')],use=pairwise.complete.obs)$correlations modMat = matrix(c( 'exposure - intent', 'gam11',NA, 'benefit - intent', 'gam12',NA, 'norms - intent', 'gam13',NA, 'childBarrier - intent', 'gam14',NA, 'parentBarrier - intent', 'gam15',NA, 'knowBenefit - intent', 'gam16',NA, 'intent-intent','psi11',NA, 'intent-recuse','gam21',NA, 'recuse-recuse','psi22',NA), ncol=3,byrow=T) model4 = sem(modMat,corr,N=1520,fixed.x=c('exposure','benefit','norms','childBarrier' , 'parentBarrier','knowBenefit')) Is this correctly modeling my diagram? I'm not sure if a) I'm dealing with the categorical variable correctly, or b) whether fixed.x is accurately modeling the correlations for me. Any help would be appreciated. I'm also looking into creating a plot function within R (similar to the path.diagram function, but using R plots). If I get something useful I'll try and post it back __ 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] Path Analysis
Dear Sam, -Original Message- From: R Help [mailto:rhelp.st...@gmail.com] Sent: May-24-10 1:04 PM To: John Fox Cc: r-help Subject: Re: [R] Path Analysis That's an interesting idea, I got the same impression from your SEM appendix to Companion to applied regression in the paragraph just before Section 3. So I could get the same results if I built the following two models: Not really the same results, but the models are similar. mod1 = lm(intent~exposure+benefit+norms+childBarrier+parentBarrier+knowBenefit,data = dat) mod2 = glm(recuse~intent+norms+exposure+childBarrier+parentBarrier,data=dat,family= b inomial(link=logit)) And in the second model only the intent should have a significant coefficient? Yes, if you're right that the effects of the other variables are entirely mediated by intent. When I run those models I get a number of significant findings in the mod2. Does that mean that I have mis-specified my model? If so (and I think I have), can I postulate that there is a link between each significant coefficient? With the usual caveats about significance and interpreting regressions causally, large coefficients for the other variables suggests that their effects are not wholly mediated by intent. Best, John Thanks so much for your input, Sam Stewart summary(mod2) Call: glm(formula = recuse ~ intent + norms + exposure + childBarrier + parentBarrier, family = binomial(link = logit), data = dat) Deviance Residuals: Min 1Q Median 3Q Max -2.2784 -0.9018 0.5899 0.7686 1.9314 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) -2.512690.50359 -4.990 6.05e-07 *** intent 0.595740.08345 7.139 9.39e-13 *** norms 0.238220.02991 7.964 1.67e-15 *** exposure 0.125220.08613 1.454 0.145981 childBarrier -0.312960.08693 -3.600 0.000318 *** parentBarrier -0.234000.08676 -2.697 0.006995 ** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 1803.0 on 1479 degrees of freedom Residual deviance: 1567.8 on 1474 degrees of freedom (40 observations deleted due to missingness) AIC: 1579.8 Number of Fisher Scoring iterations: 4 On Mon, May 24, 2010 at 1:17 PM, John Fox j...@mcmaster.ca wrote: Dear sstewart, The model appears to reflect the path diagram, assuming that you intend to allow the exogenous variables to be correlated and want the errors to be uncorrelated. This is one way to model the binary variable reuse. An alternative would be to fit the equation for intent by least-squares regression (assuming that the relationships are linear, etc.), and the equation of reuse by, e.g., logistic regression (again assuming that the model is correctly specified). If you're right that the effects of the exogenous variables are entirely mediated by intent, then if you put these variables in the equation for reuse, their coefficients should be small. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of R Help Sent: May-24-10 11:18 AM To: r-help Subject: [R] Path Analysis Hello list, I'm trying to make sure that I'm performing a path analysis correctly using the sem package. the figure at http://flame.cs.dal.ca/~sstewart/regressDiag.png has a detailing of the model. The challenge I'm having is that reuse is an indicator (0/1) variable. Here's the code I'm using: corr = hetcor(dat[,c('intent','exposure','benefit','norms','childBarrier','parentBa r rier','knowBenefit','recuse')],use=pairwise.complete.obs)$correlations modMat = matrix(c( 'exposure - intent', 'gam11',NA, 'benefit - intent', 'gam12',NA, 'norms - intent', 'gam13',NA, 'childBarrier - intent', 'gam14',NA, 'parentBarrier - intent', 'gam15',NA, 'knowBenefit - intent', 'gam16',NA, 'intent-intent','psi11',NA, 'intent-recuse','gam21',NA, 'recuse-recuse','psi22',NA), ncol=3,byrow=T) model4 = sem(modMat,corr,N=1520,fixed.x=c('exposure','benefit','norms','childBarrier' , 'parentBarrier','knowBenefit')) Is this correctly modeling my diagram? I'm not sure if a) I'm dealing with the categorical variable correctly, or b) whether fixed.x is accurately modeling the correlations for me. Any help would be appreciated. I'm also looking into creating a plot function within R (similar to the path.diagram function, but using R plots). If I get something useful I'll try and post it back __ R
[R] path analysis in R (standardized solution)
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? __ 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] path analysis (misspecification?)
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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 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.
Re: [R] path analysis (misspecification?)
thank you very much! I definitely need more theoretical background ... but for now; what does that mean for this dataset? x1 should be the intermediate variable of x2 and y1 (x2 - x1 - y1) Can I test that with this kind of analysis? or do I see know that this kind of intermediate variable model does not fit the data well and I need to set all paths to get a good model that represents the data good enough? Am 09.03.2009 um 06:15 schrieb William Revelle: 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.