[R] plotting lines on old graph after par(new=TRUE)
Hi, In my work, I often investigate relationships between highly skewed data. Example: set.seed(111) require(MASS) d = data.frame(mvrnorm(1000, mu=c(0,0), Sigma=matrix(c(1,.6,.6,1), nrow=2))) names(d) = c(x,y) ## Skew Y d$y = d$y^4 plot(d$x, d$y) lines(lowess(d$x, d$y), lwd=2, col=blue) Unfortunately, with such skewed data, it's hard to see the line unless we zoom in, by either ignoring the outliers, or breaking the scale of the y axis, such that the first 2/3 of the graph correspond to a normal scale, and the remaining 1/3 correspond to a compressed scale. (I know this is generally not recommended, see http://r.789695.n4.nabble.com/split-a-y-axis-to-show-data-on-different-scales-td805816.html). I created a function to do this: scaleBreak = function(x,y,axis=2, breakpos=1,...){ figure out which Y values are above the breakpos y_above = y[ybreakpos]; x_above = x[ybreakpos] y_below = y[y=breakpos]; x_below = x[y=breakpos] pick ranges range_1 = range(y_below) range_2 = range(y_above) find limits of y axis (so it spans 2/3rds) mx = max(y_below); mn = min(y_below) ylims1 = c(mn, mx + (mx-mn)/2) plot bottom graph plot(range(x), ylims1, type=n, yaxt=n,...) points(x_below, y_below, yaxt=n,...) axis(2, pretty(y_below)) min2 = (breakpos + .45*breakpos - max(y))/.45 add second graph par(new=TRUE) plot(range(x), c(min2, max(y)), type=n, yaxt=n, xaxt=n, ylab=, axes=F) points(x_above, y_above, yaxt=n,...) axis(2, pretty(y_above)[-1]) require(plotrix) axis.break(axis=axis, breakpos) } The problem I'm having is that the fitted line is not printed on the scale of the bottom 2/3 plot: scaleBreak(d$x, d$y, breakpos=20) lines(lowess(d$x, d$y), lwd=2, col=blue) Can anyone think of a solution where the line is on the scale of the bottom 2/3 of the plot, in the right location? (Again, let me preempt the objections others might raise about how this should not be done. I know it generally should not be done, but let's pretend I have an excellent reason :) ) 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.
[R] automatically replacing the third period with a break
I've got a dataset with really long column names (e.g., CYJ.OSU.OAV.UJC.BUT.RDI). What I'd like to do is replace the fourth period with a break (\n) so that when it plots, it will not run off the page. Here's what I've got so far: create fake names function fake.names = function(x){ paste0(LETTERS[sample(1:26,3)], collapse=) } create the fake names fake = paste0(unlist(lapply(1:6, fake.names)), collapse=.) replace fourth period with \n gsub([[:alnum:]]\\.[[:alnum:]]+\\.[[:alnum:]]+\\.[[:alnum:]]+\\., [[:alnum:]]\\.[[:alnum:]]+\\.[[:alnum:]]+\\.[[:alnum:]]+\n,fake) which results in something like: TW[[:alnum:]].[[:alnum:]]+.[[:alnum:]]+.[[:alnum:]]+\nNQJ.VSI Any ideas on how to make it replace that? [[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] automatically replacing the third period with a break
Perfect. Thanks! On Tue, Mar 18, 2014 at 2:26 PM, Thomas Lumley tlum...@uw.edu wrote: On Tue, Mar 18, 2014 at 12:43 PM, Dustin Fife fife.dus...@gmail.comwrote: I've got a dataset with really long column names (e.g., CYJ.OSU.OAV.UJC.BUT.RDI). What I'd like to do is replace the fourth period with a break (\n) so that when it plots, it will not run off the page. Here's what I've got so far: create fake names function fake.names = function(x){ paste0(LETTERS[sample(1:26,3)], collapse=) } create the fake names fake = paste0(unlist(lapply(1:6, fake.names)), collapse=.) Backreferences cat( gsub((([[:alnum:]]+\\.){3})([[:alnum:]]+)\\., \\1\\2\n, fake ) ) That is, match three word/period sequences, match a word, match a period, and output the first two things. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland [[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] turn string into expression for paste
do.call did it. (and I learned a new function!) Thanks for the help, everyone. On Tue, Feb 11, 2014 at 2:24 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps: Var1 - LETTERS[1:3] Var2 - 1:2 do.call(paste0,expand.grid(lapply(VarNames,get))) #[1] A1 B1 C1 A2 B2 C2 A.K. On Tuesday, February 11, 2014 3:18 PM, Dustin Fife fife.dus...@gmail.com wrote: I have a list of variables of a variable length (e.g., Var1, Var2, Var3, ... Vark). What I want to do is somehow feed that information into the paste function, like: paste(Var1, Var2, Var3...) The problem is that I don't want to hard-code it because it's wrapped within a function. Is there a way to supply a string? e.g., k = 2 VarNames = paste0(Var, 1:k) paste(someFunction(VarNames), collapse=) Suppose Var1 = A, B, C and Var2 = 1, 2. The result should return A1, A2, B1, B2, C1, C2. I've tried using eval, and get, but with no luck. Thanks in advance! Dustin [[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.
[R] turn string into expression for paste
I have a list of variables of a variable length (e.g., Var1, Var2, Var3, ... Vark). What I want to do is somehow feed that information into the paste function, like: paste(Var1, Var2, Var3...) The problem is that I don't want to hard-code it because it's wrapped within a function. Is there a way to supply a string? e.g., k = 2 VarNames = paste0(Var, 1:k) paste(someFunction(VarNames), collapse=) Suppose Var1 = A, B, C and Var2 = 1, 2. The result should return A1, A2, B1, B2, C1, C2. I've tried using eval, and get, but with no luck. Thanks in advance! Dustin [[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] avoiding multiple actual arguments in default function behavior
Suppose I'm creating a function that sets default ylab and xlab behaviors: plotx = function(x, y, ...){ plot(x,y, ylab=, xlab=,...) } The problem is, on occasion, I actually want to override the defaults in my function. I would like to do the following: plotx(1:100, 1:100, xlab=I Don't Work!) But I get the multiple actual arguments error message (which makes sense). Does anyone know how to set a default (like plotx does), but allow it to change if the user specifies the same argument via ...? I tried doing something like this: plotx = function(x, y, ...){ args = list(...) yl = ifelse(!is.null(args$ylab), args$ylab, ) xl = ifelse(!is.null(args$xlab), args$xlab, ) plot(x,y, ylab=yl, xlab=xl,...) } but got the same error. I then started thinking that maybe I can remove the ylab and xlab arguments from ..., but I don't know how I'd do that. Any ideas of how to remove it? Or, is there a better way of doing this? 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.
Re: [R] avoiding multiple actual arguments in default function behavior
That's a good idea, but I'm hoping there's another way. The actual function that I'm using sets LOTS of default behaviors and I try to minimize the number of arguments I have. On Wed, Feb 5, 2014 at 10:19 AM, William Dunlap wdun...@tibco.com wrote: Suppose I'm creating a function that sets default ylab and xlab behaviors: plotx = function(x, y, ...){ plot(x,y, ylab=, xlab=,...) } The problem is, on occasion, I actually want to override the defaults in my function. Make xlab and ylab arguments to your function. plotx2 - function(x, y, ..., xlab=, ylab=) { plot(x, y, xlab=xlab, ylab=ylab, ...) } (I put them after the ... in the argument list so they must be fully named in the call.) Bill Dunlap TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dustin Fife Sent: Wednesday, February 05, 2014 8:11 AM To: r-help Subject: [R] avoiding multiple actual arguments in default function behavior Suppose I'm creating a function that sets default ylab and xlab behaviors: plotx = function(x, y, ...){ plot(x,y, ylab=, xlab=,...) } The problem is, on occasion, I actually want to override the defaults in my function. I would like to do the following: plotx(1:100, 1:100, xlab=I Don't Work!) But I get the multiple actual arguments error message (which makes sense). Does anyone know how to set a default (like plotx does), but allow it to change if the user specifies the same argument via ...? I tried doing something like this: plotx = function(x, y, ...){ args = list(...) yl = ifelse(!is.null(args$ylab), args$ylab, ) xl = ifelse(!is.null(args$xlab), args$xlab, ) plot(x,y, ylab=yl, xlab=xl,...) } but got the same error. I then started thinking that maybe I can remove the ylab and xlab arguments from ..., but I don't know how I'd do that. Any ideas of how to remove it? Or, is there a better way of doing this? 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.
Re: [R] avoiding multiple actual arguments in default function behavior
Perfect. Thanks! On Wed, Feb 5, 2014 at 10:35 AM, arun smartpink...@yahoo.com wrote: Hi, Try: plotx - function(x,y, ...){ labels - list(xlab=x,ylab=y) args - modifyList(labels,list(x=x,...)) do.call(plot,args) } plotx(1:100,1:100,xlab=I Don't Work!) A.K. On Wednesday, February 5, 2014 11:14 AM, Dustin Fife fife.dus...@gmail.com wrote: Suppose I'm creating a function that sets default ylab and xlab behaviors: plotx = function(x, y, ...){ plot(x,y, ylab=, xlab=,...) } The problem is, on occasion, I actually want to override the defaults in my function. I would like to do the following: plotx(1:100, 1:100, xlab=I Don't Work!) But I get the multiple actual arguments error message (which makes sense). Does anyone know how to set a default (like plotx does), but allow it to change if the user specifies the same argument via ...? I tried doing something like this: plotx = function(x, y, ...){ args = list(...) yl = ifelse(!is.null(args$ylab), args$ylab, ) xl = ifelse(!is.null(args$xlab), args$xlab, ) plot(x,y, ylab=yl, xlab=xl,...) } but got the same error. I then started thinking that maybe I can remove the ylab and xlab arguments from ..., but I don't know how I'd do that. Any ideas of how to remove it? Or, is there a better way of doing this? 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. [[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] Numeric Column Labels in Excel Function
Hi all, I frequently get requests to do data analysis where the person references an excel column. e.g., I want to analyze [insert complex variable name], located at column AAQ in Excel. I've been doing is gsub and inserting a part of the string for the complex variable name, then going from there. But, I was trying to make function that returns the following vector: excelVector = A, B, C, D,...AA, AB, AC...ZA, ZB, ZC,...AAA, AAB, AAC, etc. In other words, the argument would have one argument (n, or the number of columns), then it would return a list like that shown above. Then, all I would have to do is column.of.interest = which(excelVector==AAQ) But I'm a bit stumped. The first part is easy: LETTERS[1:26] The next would probably use expand.grid, but all my potential solutions are pretty clunky. 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.
Re: [R] Numeric Column Labels in Excel Function
There seems to be a problem with that function: object 'vec1' not found. On Mon, Jan 27, 2014 at 4:05 PM, arun smartpink...@yahoo.com wrote: HI, May be you can try: fun1 - function(n){ if(n =26){ res - LETTERS[seq_len(n)] } else if(n26 n =702){ res - c(LETTERS,apply(expand.grid(vec1,vec1)[,2:1],1,paste,collapse=))[1:n] } else if(n 702 n =18278){ res - c(LETTERS,apply(expand.grid(vec1,vec1)[,2:1],1,paste,collapse=),apply(expand.grid(vec1,vec1,vec1)[,3:1],1,paste,collapse=))[1:n] } else { NA } res } fun1(0) #character(0) fun1(2) #[1] A B fun1(28) A.K. On Monday, January 27, 2014 4:41 PM, Dustin Fife fife.dus...@gmail.com wrote: Hi all, I frequently get requests to do data analysis where the person references an excel column. e.g., I want to analyze [insert complex variable name], located at column AAQ in Excel. I've been doing is gsub and inserting a part of the string for the complex variable name, then going from there. But, I was trying to make function that returns the following vector: excelVector = A, B, C, D,...AA, AB, AC...ZA, ZB, ZC,...AAA, AAB, AAC, etc. In other words, the argument would have one argument (n, or the number of columns), then it would return a list like that shown above. Then, all I would have to do is column.of.interest = which(excelVector==AAQ) But I'm a bit stumped. The first part is easy: LETTERS[1:26] The next would probably use expand.grid, but all my potential solutions are pretty clunky. 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. __ 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 densities outside axis
That's perfect. Thanks! On Fri, Sep 6, 2013 at 12:45 AM, Pascal Oettli kri...@ymail.com wrote: Hello, Using a web search engine, I found, for example: http://www.unt.edu/benchmarks/archives/2003/february03/rss.htm http://sas-and-r.blogspot.jp/2012_09_01_archive.html Hope this helps, Pascal 2013/9/5 Dustin Fife df...@ou.edu I've been working on a way to visualize a spearman correlation. That seemed pretty simple: generate skewed data x = rnorm(100)^2 y = .6*x + rnorm(100, 0, sqrt(1-.6^2)) plot(x,y) regular plot plot(rank(x),rank(y), xaxt=n, yaxt=n) ### spearman-like plot make axis labels axis(1, at=quantile(rank(x)), labels=round(quantile(x), digits=2)) axis(2, at=quantile(rank(y)), labels=round(quantile(y), digits=2)) However, transforming the data into ranks eliminates any information we have about the distributions of the data. My solution to this problem is to plot the densities outside the x/y axis with the mode of the distribution pointing away from the plot. I've seen plots like this in textbooks, but can't think of a way to do this in R. Any ideas? [[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.
[R] plot densities outside axis
I've been working on a way to visualize a spearman correlation. That seemed pretty simple: generate skewed data x = rnorm(100)^2 y = .6*x + rnorm(100, 0, sqrt(1-.6^2)) plot(x,y) regular plot plot(rank(x),rank(y), xaxt=n, yaxt=n) ### spearman-like plot make axis labels axis(1, at=quantile(rank(x)), labels=round(quantile(x), digits=2)) axis(2, at=quantile(rank(y)), labels=round(quantile(y), digits=2)) However, transforming the data into ranks eliminates any information we have about the distributions of the data. My solution to this problem is to plot the densities outside the x/y axis with the mode of the distribution pointing away from the plot. I've seen plots like this in textbooks, but can't think of a way to do this in R. Any ideas? [[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] stepAIC with logistf function
Hi, I'm doing research with biodata where I'm trying to predict disease state from many biomarkers. Unfortunately it's not a common disease, so the sample size is small. When I run the model as a glm, it has separation issues. Consequently, I ran the model using logistf with no problems. Now, however, I want to use the stepAIC function, but it doesn't recognize logistf as an lm or glm object. What I'm wondering is if there's a way to still do stepAIC with this package. Can I just convert the logistf results to a glm object? Is there already a function that is able to work with this package? I've seen that someone asked a similar question here: http://r.789695.n4.nabble.com/model-selection-using-logistf-package-td3846958.html That question was answered, but the response didn't have much of an explanation and I'm not sure that it would apply with AIC selection. Thanks in advance for the help! Dustin [[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] problem with pan package?
Hi, I'm not sure if this is a question for just the maintainer, but I'm having issues with the pan package. Using the author's example code *data(marijuana) # we only use the complete data to illustrate marijuana - subset(marijuana,!is.na(y)) attach(marijuana) pred - with(marijuana,cbind(int,dummy1,dummy2,dummy3,dummy4,dummy5)) xcol - 1:6 zcol - 1 # Now we can fit the model. result - ecme(y,subj,occ,pred,xcol,zcol)* It works just fine. But, if you comment out the third line *#marijuana - subset(marijuana,!is.na(y))* I get an error *Error in ecme(y, subj, occ, pred, xcol, zcol) : NA/NaN/Inf in foreign function call (arg 26)* The problem is that ecme is an imputation algorithm. But it only works if there's no missing data on y. Is there any way around this? Or is it just a coding error on the part of the maintainer? Dustin P.S. I'm using R 2.15.3 and I just installed the pan package today (version .6) -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] identify non-recursive models
Hi, I'm working on a project that will generate RAM matrices at random. What I want to do is to be able to automatically identify if the model is non-recursive. For example, the following RAM matrix has a non-recursive loop (going from A to B to C to A): n.recursive - data.frame(matrix(c(A, B, 1, B, C, 1, C, A, 1, B, D, 1), nrow=4, byrow=TRUE)) names(n.recursive) - c(From, To, Arrows) What I want to be able to do is have a function that automatically checks whether there is a non-recursive path. Here's what I've thought of so far: 1. Find all variables that both send and receive an arrow. (in this case, A and B both fit that criteria). vars - LETTERS[1:5] double.arrow.vars - vars[which(vars %in% n.recursive$From vars %in% n.recursive$To)] 2. For all variables found in #1, follow all paths exiting that variable to other variables, then follow all paths exiting that next variable variable, etc. and continue tracing the path. # insert complicated code here 3. If a variable is repeated, identify it as non-recursive. The problem with #2 is that, for large models, the number of paths to be traced could be really large. (Also, I'm having trouble thinking of how to code it so it's not really awkward). So, my question is this: is there a better way to approach the problem? Is there a more efficient way? I know that I could probably identify which models are non-recursive after estimation (via convergence failures or negative parameter estimates). But I want to be able to identify them before estimation. Any help would be appreciated. Dustin -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] identify non-recursive models
Thanks for the response. That doesn't seem to do it. It's able to identify if one edge connects back into itself, but isn't able to identify whether an edge eventually connects back into itself (after passing through multiple variables). For example, the following should fail, because the path goes from 1-2-3, then back into 1: is.simple(graph(c(1,2,2,3,3,1,3,4))) But, it returns TRUE. On Tue, Jan 29, 2013 at 10:21 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 29/01/2013 11:12 AM, Dustin Fife wrote: Hi, I'm working on a project that will generate RAM matrices at random. What I want to do is to be able to automatically identify if the model is non-recursive. For example, the following RAM matrix has a non-recursive loop (going from A to B to C to A): I'm not familiar with your terms, but your description sounds like you want a test for a simple graph. I believe the igraph package has that in the is.simple function (and a lot of other tests of graph properties in case that's not the one you want). Duncan Murdoch n.recursive - data.frame(matrix(c(A, B, 1, B, C, 1, C, A, 1, B, D, 1), nrow=4, byrow=TRUE)) names(n.recursive) - c(From, To, Arrows) What I want to be able to do is have a function that automatically checks whether there is a non-recursive path. Here's what I've thought of so far: 1. Find all variables that both send and receive an arrow. (in this case, A and B both fit that criteria). vars - LETTERS[1:5] double.arrow.vars - vars[which(vars %in% n.recursive$From vars %in% n.recursive$To)] 2. For all variables found in #1, follow all paths exiting that variable to other variables, then follow all paths exiting that next variable variable, etc. and continue tracing the path. # insert complicated code here 3. If a variable is repeated, identify it as non-recursive. The problem with #2 is that, for large models, the number of paths to be traced could be really large. (Also, I'm having trouble thinking of how to code it so it's not really awkward). So, my question is this: is there a better way to approach the problem? Is there a more efficient way? I know that I could probably identify which models are non-recursive after estimation (via convergence failures or negative parameter estimates). But I want to be able to identify them before estimation. Any help would be appreciated. Dustin [[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] identify non-recursive models
That looks like exactly what I need. I tested it on my PC and it ran, but my mac couldn't find the function is.dag. Any ideas? On Tue, Jan 29, 2013 at 11:03 AM, William Dunlap wdun...@tibco.com wrote: is.dag()? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dustin Fife Sent: Tuesday, January 29, 2013 8:52 AM To: Duncan Murdoch Cc: r-help Subject: Re: [R] identify non-recursive models Thanks for the response. That doesn't seem to do it. It's able to identify if one edge connects back into itself, but isn't able to identify whether an edge eventually connects back into itself (after passing through multiple variables). For example, the following should fail, because the path goes from 1-2-3, then back into 1: is.simple(graph(c(1,2,2,3,3,1,3,4))) But, it returns TRUE. On Tue, Jan 29, 2013 at 10:21 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 29/01/2013 11:12 AM, Dustin Fife wrote: Hi, I'm working on a project that will generate RAM matrices at random. What I want to do is to be able to automatically identify if the model is non-recursive. For example, the following RAM matrix has a non-recursive loop (going from A to B to C to A): I'm not familiar with your terms, but your description sounds like you want a test for a simple graph. I believe the igraph package has that in the is.simple function (and a lot of other tests of graph properties in case that's not the one you want). Duncan Murdoch n.recursive - data.frame(matrix(c(A, B, 1, B, C, 1, C, A, 1, B, D, 1), nrow=4, byrow=TRUE)) names(n.recursive) - c(From, To, Arrows) What I want to be able to do is have a function that automatically checks whether there is a non-recursive path. Here's what I've thought of so far: 1. Find all variables that both send and receive an arrow. (in this case, A and B both fit that criteria). vars - LETTERS[1:5] double.arrow.vars - vars[which(vars %in% n.recursive$From vars %in% n.recursive$To)] 2. For all variables found in #1, follow all paths exiting that variable to other variables, then follow all paths exiting that next variable variable, etc. and continue tracing the path. # insert complicated code here 3. If a variable is repeated, identify it as non-recursive. The problem with #2 is that, for large models, the number of paths to be traced could be really large. (Also, I'm having trouble thinking of how to code it so it's not really awkward). So, my question is this: is there a better way to approach the problem? Is there a more efficient way? I know that I could probably identify which models are non-recursive after estimation (via convergence failures or negative parameter estimates). But I want to be able to identify them before estimation. Any help would be appreciated. Dustin [[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. -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] identify non-recursive models
I did have it loaded with the newest version of igraph, but apparently it requires the newest version of R. I now have R-2.15.2 loaded and it works! Thanks for all the help! Dustin On Tue, Jan 29, 2013 at 11:21 AM, William Dunlap wdun...@tibco.com wrote: Is package:igraph loaded in your R session on the mac? Is it up to date? (I would doubt that is.dag would be a recently written function.) ** ** Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com ** ** *From:* Dustin Fife [mailto:fife.dus...@gmail.com] *Sent:* Tuesday, January 29, 2013 9:16 AM *To:* William Dunlap *Cc:* Duncan Murdoch; r-help *Subject:* Re: [R] identify non-recursive models ** ** That looks like exactly what I need. I tested it on my PC and it ran, but my mac couldn't find the function is.dag. Any ideas? On Tue, Jan 29, 2013 at 11:03 AM, William Dunlap wdun...@tibco.com wrote: is.dag()? Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dustin Fife Sent: Tuesday, January 29, 2013 8:52 AM To: Duncan Murdoch Cc: r-help Subject: Re: [R] identify non-recursive models Thanks for the response. That doesn't seem to do it. It's able to identify if one edge connects back into itself, but isn't able to identify whether an edge eventually connects back into itself (after passing through multiple variables). For example, the following should fail, because the path goes from 1-2-3, then back into 1: is.simple(graph(c(1,2,2,3,3,1,3,4))) But, it returns TRUE. On Tue, Jan 29, 2013 at 10:21 AM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 29/01/2013 11:12 AM, Dustin Fife wrote: Hi, I'm working on a project that will generate RAM matrices at random. What I want to do is to be able to automatically identify if the model is non-recursive. For example, the following RAM matrix has a non-recursive loop (going from A to B to C to A): I'm not familiar with your terms, but your description sounds like you want a test for a simple graph. I believe the igraph package has that in the is.simple function (and a lot of other tests of graph properties in case that's not the one you want). Duncan Murdoch n.recursive - data.frame(matrix(c(A, B, 1, B, C, 1, C, A, 1, B, D, 1), nrow=4, byrow=TRUE)) names(n.recursive) - c(From, To, Arrows) What I want to be able to do is have a function that automatically checks whether there is a non-recursive path. Here's what I've thought of so far: 1. Find all variables that both send and receive an arrow. (in this case, A and B both fit that criteria). vars - LETTERS[1:5] double.arrow.vars - vars[which(vars %in% n.recursive$From vars %in% n.recursive$To)] 2. For all variables found in #1, follow all paths exiting that variable to other variables, then follow all paths exiting that next variable variable, etc. and continue tracing the path. # insert complicated code here 3. If a variable is repeated, identify it as non-recursive. The problem with #2 is that, for large models, the number of paths to be traced could be really large. (Also, I'm having trouble thinking of how to code it so it's not really awkward). So, my question is this: is there a better way to approach the problem? Is there a more efficient way? I know that I could probably identify which models are non-recursive after estimation (via convergence failures or negative parameter estimates). But I want to be able to identify them before estimation. Any help would be appreciated. Dustin [[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. -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] sem package, suppress warnings
Perfect! That did it, and I learned a new function :) On Sun, Jan 20, 2013 at 2:49 PM, John Fox j...@mcmaster.ca wrote: Dear Dustin and Steve, For some reason, I didn't see Dustin's original message. As documented in ?sem, the warn argument to sem() covers only warnings directly produced by the optimizer, warn: if TRUE, warnings produced by the optimization function will be printed. This should generally not be necessary, since sem prints its own warning, and saves information about convergence. The default is FALSE. It doesn't cover the warnings produced by sem() itself. For that, you can do as Steve suggests, or simply set options(warn = -1). The debug argument is FALSE by default and if TRUE prints the iteration history and some additional information; it is irrelevant to warnings. I hope this helps, 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 Steve Taylor Sent: Sunday, January 20, 2013 3:22 PM To: Dustin Fife; r-help Subject: Re: [R] sem package, suppress warnings Have you tried suppressWarnings(sem(mod, S = as.matrix(dataset), N = 1000, maxiter = 1, warn = FALSE)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dustin Fife Sent: Saturday, 19 January 2013 5:32a To: r-help Subject: [R] sem package, suppress warnings Hi, I'm using the sem package under conditions where I know beforehand that several models will be problematic. Because of that, I want to suppress warnings. I've used the following code sem(mod, S = as.matrix(dataset), N = 1000, maxiter = 1, warn = FALSE) But I still get warnings. I've also tried adding check.analytic = FALSE, debug = FALSE, and that doesn't seem to do it either. Any ideas why it's not working? It may be important to note that the command above is wrapped within a function and I'm using try() to avoid errors. Thanks in advance! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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. [[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] sem package, suppress warnings
Hi, I'm using the sem package under conditions where I know beforehand that several models will be problematic. Because of that, I want to suppress warnings. I've used the following code sem(mod, S = as.matrix(dataset), N = 1000, maxiter = 1, warn = FALSE) But I still get warnings. I've also tried adding check.analytic = FALSE, debug = FALSE, and that doesn't seem to do it either. Any ideas why it's not working? It may be important to note that the command above is wrapped within a function and I'm using try() to avoid errors. Thanks in advance! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] mfrow and centering plots when there's an odd number
Let me start with an example: par(mfrow=c(2,3)) for (i in 1:5){ x = rnorm(100) y = .5*x + rnorm(100, 0, sqrt(1-.5^2)) plot(x,y) } Note that there's five plots and six spaces for those plots via mfrow, leaving one row empty. Is there a way to have the bottom two plots centered? I think it looks weird to have them left-justified. Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] mfrow and centering plots when there's an odd number
That's perfect! Thanks for the help. For those in the future who may have a similar question, here's how I did it: nf - layout(matrix(c(1,1,2,2,3,3,0,4,4,5,5,0), 2, 6, byrow=TRUE), respect=FALSE) for (i in 1:5){ x = rnorm(100) y = .5*x + rnorm(100, 0, sqrt(1-.5^2)) plot(x,y) } On Mon, Jul 9, 2012 at 6:03 PM, R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com wrote: Take a look at ?layout Michael On Jul 9, 2012, at 5:15 PM, Dustin Fife fife.dus...@gmail.com wrote: Let me start with an example: par(mfrow=c(2,3)) for (i in 1:5){ x = rnorm(100) y = .5*x + rnorm(100, 0, sqrt(1-.5^2)) plot(x,y) } Note that there's five plots and six spaces for those plots via mfrow, leaving one row empty. Is there a way to have the bottom two plots centered? I think it looks weird to have them left-justified. Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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. -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] propensity score matching estimates?
I'm using the Match package to do propensity score matching. Here's some example code that shows the problem that I'm having (much of this code is taken from the Match package documentation): *data(lalonde) glm1 - glm(treat~age + I(age^2) + educ + I(educ^2) + black + hisp + married + nodegr + re74 + I(re74^2) + re75 + I(re75^2) + u74 + u75, family=binomial, data=lalonde) X - glm1$fitted Y - lalonde$re78 Tr - lalonde$treat # one-to-one matching with replacement (the M=1 option). # Estimating the treatment effect on the treated (the estimand option defaults to ATT). rr - Match(Y=Y, Tr=Tr, X=X, M=1);* And here's where the 'problem' occurs: *summary(rr) # gives an estimate of 2153.3 mean(rr$mdata$Y[rr$index.treated])-mean(rr$mdata$Y[rr$index.control]) # gives an estimate of 1083.848 * Notice that when I simply subtract the means from one another, I get a different estimate (1083.848) than when the algorithm outputs (2153.3). It seems that the obvious answer is that I'm not computing the estimate properly. If so, how is it computed? One more related question. I'm actually trying to do propensity score matching to estimate the effect of treatment on a dichotomous variable. Would the function change at all if the estimated effect is on a dichotomous scale? -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] setting parameters equal in lm
That did it. Thanks! One more follow-up questions. How do I set a parameter to a particular value? I tried I(.5*X2), but that didn't do what I expected. On Tue, May 29, 2012 at 6:39 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Your model is equivalent of y = b1(X1 + X3) + b2X2 (plus error) So, use I() to add X1 and X3. You don't need to create an extra variable X13 - X1 + X3. See the help page for it. The point on function formula. ?I linMod2 = lm(Y ~ -1 + I(X1 + X3) + X2, data=data.set) summary(linMod2) # The same. linMod3 = lm(Y ~ 0 + I(X1 + X3) + X2, data=data.set) summary(linMod3) With set.seed(1) your common slope is coef(linMod2) I(X1 + X3) X2 0.4237869 3.3626984 Also, I find it better to put 'library', 'require', etc as the first lines of code. Hope this helps, Rui Barradas Em 29-05-2012 04:14, Dustin Fife escreveu: Forgive me if this is a trivial question, but I couldn't find it an answer in former forums. I'm trying to reproduce some SAS results where they set two parameters equal. For example: y = b1X1 + b2X2 + b1X3 Notice that the variables X1 and X3 both have the same slope and the intercept has been removed. How do I get an estimate of this regression model? I know how to remove the intercept (-1 somewhere after the tilde). But how about setting parameters equal? I have used the car package to set up linear hypotheses: X1 = rnorm(20, 10, 5); X2 = rnorm(20, 10, 5); X3 = rnorm(20, 10, 5) Y = .5*X1 + 3*X2 + .5*X3 + rnorm(20, 0, 15) data.set = data.frame(cbind(X1, X2, X3, Y)) linMod = lm(Y~X1 + X2 + X3, data=data.set) require(car) linearHypothesis(linMod, c((Intercept)=0, X1-X3=0)) (forgive the unconventional use of the equal signold habit). Unfortunately, the linearHypothesis is always compared to a full model (where the parameters are freely estimated). I want to have an ANOVA summary table for the reduced model. Any ideas? Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] setting parameters equal in lm
Great. Thank you! On Tue, May 29, 2012 at 8:11 AM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote: offset() fixes the parameter to 1. So offset(I(.5*X2)) should do the trick. 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 -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Dustin Fife Verzonden: dinsdag 29 mei 2012 14:56 Aan: Rui Barradas CC: r-help Onderwerp: Re: [R] setting parameters equal in lm That did it. Thanks! One more follow-up questions. How do I set a parameter to a particular value? I tried I(.5*X2), but that didn't do what I expected. On Tue, May 29, 2012 at 6:39 AM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Your model is equivalent of y = b1(X1 + X3) + b2X2 (plus error) So, use I() to add X1 and X3. You don't need to create an extra variable X13 - X1 + X3. See the help page for it. The point on function formula. ?I linMod2 = lm(Y ~ -1 + I(X1 + X3) + X2, data=data.set) summary(linMod2) # The same. linMod3 = lm(Y ~ 0 + I(X1 + X3) + X2, data=data.set) summary(linMod3) With set.seed(1) your common slope is coef(linMod2) I(X1 + X3) X2 0.4237869 3.3626984 Also, I find it better to put 'library', 'require', etc as the first lines of code. Hope this helps, Rui Barradas Em 29-05-2012 04:14, Dustin Fife escreveu: Forgive me if this is a trivial question, but I couldn't find it an answer in former forums. I'm trying to reproduce some SAS results where they set two parameters equal. For example: y = b1X1 + b2X2 + b1X3 Notice that the variables X1 and X3 both have the same slope and the intercept has been removed. How do I get an estimate of this regression model? I know how to remove the intercept (-1 somewhere after the tilde). But how about setting parameters equal? I have used the car package to set up linear hypotheses: X1 = rnorm(20, 10, 5); X2 = rnorm(20, 10, 5); X3 = rnorm(20, 10, 5) Y = .5*X1 + 3*X2 + .5*X3 + rnorm(20, 0, 15) data.set = data.frame(cbind(X1, X2, X3, Y)) linMod = lm(Y~X1 + X2 + X3, data=data.set) require(car) linearHypothesis(linMod, c((Intercept)=0, X1-X3=0)) (forgive the unconventional use of the equal signold habit). Unfortunately, the linearHypothesis is always compared to a full model (where the parameters are freely estimated). I want to have an ANOVA summary table for the reduced model. Any ideas? Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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. -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] setting parameters equal in lm
Forgive me if this is a trivial question, but I couldn't find it an answer in former forums. I'm trying to reproduce some SAS results where they set two parameters equal. For example: y = b1X1 + b2X2 + b1X3 Notice that the variables X1 and X3 both have the same slope and the intercept has been removed. How do I get an estimate of this regression model? I know how to remove the intercept (-1 somewhere after the tilde). But how about setting parameters equal? I have used the car package to set up linear hypotheses: X1 = rnorm(20, 10, 5); X2 = rnorm(20, 10, 5); X3 = rnorm(20, 10, 5) Y = .5*X1 + 3*X2 + .5*X3 + rnorm(20, 0, 15) data.set = data.frame(cbind(X1, X2, X3, Y)) linMod = lm(Y~X1 + X2 + X3, data=data.set) require(car) linearHypothesis(linMod, c((Intercept)=0, X1-X3=0)) (forgive the unconventional use of the equal signold habit). Unfortunately, the linearHypothesis is always compared to a full model (where the parameters are freely estimated). I want to have an ANOVA summary table for the reduced model. Any ideas? Thanks in advance for the help! -- Dustin Fife PhD Student Quantitative Psychology University of Oklahoma [[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] FIML with missing data in sem package
Good idea. I'll give it a try. Thanks! On Thu, Dec 1, 2011 at 6:18 AM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dustin Fife Sent: November-30-11 9:51 PM To: r-help@r-project.org Subject: [R] FIML with missing data in sem package Is there a way to use full information maximum likelihood (FIML) to estimate missing data in the sem package? For example, suppose I have a dataset with complete information on X1-X3, but missing data (MAR) on X4. Is there a way to use FIML in this case? I know lavaan and openmx allow No, the sem package doesn't handle missing data. You could, however, use another package, such as mice, for multiple imputation of the missing data. Best, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox you to do it, but I couldn't find anything in the documentation for the sem package. Thanks! -- Dustin Fife Graduate Student Quantitative Psychology University of Oklahoma [[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. -- Dustin Fife Graduate Student Quantitative Psychology University of Oklahoma [[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] FIML with missing data in sem package
What is your goal? I have used and like mice pretty well, but using mice + sem to try to address missingness seems like more work than using FIML in OpenMx or lavaan to try to address it. Is there a reason you want to use the sem package or a reason you do not want to use the others? I tried lavaan and couldn't get it to work. I noticed it was in beta so I figured it wasn't a good idea to use for simulations I intend to publish (especially when I can't get them to work properly). Either way, whether I use OpenMX or lavaan, it will require me to learn a new syntax, and I guess I'm just lazy. I'm comfortable with sem. On Thu, Dec 1, 2011 at 6:27 AM, Dustin Fife fife.dus...@gmail.com wrote: Good idea. I'll give it a try. Thanks! On Thu, Dec 1, 2011 at 6:18 AM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dustin Fife Sent: November-30-11 9:51 PM To: r-help@r-project.org Subject: [R] FIML with missing data in sem package Is there a way to use full information maximum likelihood (FIML) to estimate missing data in the sem package? For example, suppose I have a dataset with complete information on X1-X3, but missing data (MAR) on X4. Is there a way to use FIML in this case? I know lavaan and openmx allow No, the sem package doesn't handle missing data. You could, however, use another package, such as mice, for multiple imputation of the missing data. Best, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox you to do it, but I couldn't find anything in the documentation for the sem package. Thanks! -- Dustin Fife Graduate Student Quantitative Psychology University of Oklahoma [[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. -- Dustin Fife Graduate Student Quantitative Psychology University of Oklahoma [[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 Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ -- Dustin Fife Graduate Student Quantitative Psychology University of Oklahoma [[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] FIML with missing data in sem package
Is there a way to use full information maximum likelihood (FIML) to estimate missing data in the sem package? For example, suppose I have a dataset with complete information on X1-X3, but missing data (MAR) on X4. Is there a way to use FIML in this case? I know lavaan and openmx allow you to do it, but I couldn't find anything in the documentation for the sem package. Thanks! -- Dustin Fife Graduate Student Quantitative Psychology University of Oklahoma [[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.diagram in SEM--display covariances without variances
Forgive me if I'm posting to the wrong placeIt's my first time posting. Here's the situation: I'm using the sem package and making path diagrams using path.diagrams. Suppose I have the following code: #install.packages(ggm) require(ggm) cor = rcorr(7) nm = c(SOF, IWF, PWF, FSC, FSF, EF, GPA) ram = specify.model() PWF - FSF, a, NA PWF - FSC, b, NA SOF - FSF, c, NA SOF - FSC, d, NA IWF - FSF, e, NA IWF - FSC, f, NA FSC - EF, g, NA FSF - EF, h, NA EF - GPA, i, NA PWF - IWF, j, NA PWF - SOF, k, NA SOF - IWF, l, NA PWF - PWF, d1, NA SOF - SOF, d2, NA IWF - IWF, d3, NA FSC - FSC, d4, NA FSF - FSF, d5, NA EF - EF, d6, NA GPA - GPA, d7, NA sem.mod = sem(ram, cor, N=1656, obs.variables=nm) path.diagram(sem.mod, 'path/to/file/plot', ignore.double=FALSE, edge.labels=values, standardize=TRUE, min.rank=c(IWF, SOF, PWF)) The diagram is produces is hard to read because of the many variances that are shown. The covariance estimates are important for my diagram, but the variances are not. Is there a way to suppress the variance arrows without suppressing the covariance arrows? -- Dustin Fife Graduate Student, Quantitative Psychology University of Oklahoma __ 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.diagram in SEM--display covariances without variances
Thanks for the quick response...I've never edited someone else's package before. How do I go about doing that? On Wed, Nov 9, 2011 at 12:47 PM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dustin Fife Sent: November-09-11 10:57 AM To: r-help@r-project.org Subject: [R] path.diagram in SEM--display covariances without variances Forgive me if I'm posting to the wrong placeIt's my first time posting. Here's the situation: I'm using the sem package and making path diagrams using path.diagrams. Suppose I have the following code: . . . The diagram is produces is hard to read because of the many variances that are shown. The covariance estimates are important for my diagram, but the variances are not. Is there a way to suppress the variance arrows without suppressing the covariance arrows? No, but (1) pathDiagram() (the name of the function in the current version of the sem package) produces an editable text file, from which you could remove the arrows that you don't want to see; and (2) you could modify pathDiagram() -- the code for the function is, after all, available to you -- so that it does what you want. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox -- Dustin Fife Graduate Student, Quantitative Psychology University of Oklahoma __ 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. -- Dustin Fife Fife Photography www.fifephotography.com i...@fifephotography.com fife.dus...@gmail.com 405.414.5599 __ 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.diagram in SEM--display covariances without variances
Perfect! Thanks for the help. On Wed, Nov 9, 2011 at 4:27 PM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: Dustin Fife [mailto:fife.dus...@gmail.com] Sent: November-09-11 2:12 PM To: John Fox Cc: r-help@r-project.org Subject: Re: [R] path.diagram in SEM--display covariances without variances Thanks for the quick response...I've never edited someone else's package before. How do I go about doing that? I wouldn't change the sem package, but rather create your own version of pathDiagram(). You could examine the package sources, but, more simply, to see the code for the function, type its name at the command prompt: library(sem) Loading required package: MASS Loading required package: matrixcalc pathDiagram function (model, ...) { UseMethod(pathDiagram) } bytecode: 06E1CEA8 environment: namespace:sem So pathDiagram() is a generic function. What methods are available? methods(pathDiagram) [1] pathDiagram.sem* Non-visible functions are asterisked There is, therefore just one method, for objects of class sem, hidden in the sem namespace. To see it (most lines elided): sem:::pathDiagram.sem function (model, file, min.rank = NULL, max.rank = NULL, same.rank = NULL, variables = model$var.names, parameters = rownames(model$ram), ignore.double = TRUE, edge.labels = c(names, values, both), size = c(8, 8), node.font = c(Helvetica, 14), edge.font = c(Helvetica, 10), rank.direction = c(LR, TB), digits = 2, standardize = FALSE, output.type = c(graphics, dot), graphics.fmt = pdf, dot.options = NULL, ...) { . . . cat(file = handle, }\n) if (output.type == graphics !missing(file)) { cmd - paste(dot -T, graphics.fmt, -o , graph.file, , dot.options, , dot.file, sep = ) cat(Running , cmd, \n) result - try(system(cmd)) } invisible(NULL) } bytecode: 071B9568 environment: namespace:sem Just copy the functions into an editor and make whatever changes you want. Best, John On Wed, Nov 9, 2011 at 12:47 PM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dustin Fife Sent: November-09-11 10:57 AM To: r-help@r-project.org Subject: [R] path.diagram in SEM--display covariances without variances Forgive me if I'm posting to the wrong placeIt's my first time posting. Here's the situation: I'm using the sem package and making path diagrams using path.diagrams. Suppose I have the following code: . . . The diagram is produces is hard to read because of the many variances that are shown. The covariance estimates are important for my diagram, but the variances are not. Is there a way to suppress the variance arrows without suppressing the covariance arrows? No, but (1) pathDiagram() (the name of the function in the current version of the sem package) produces an editable text file, from which you could remove the arrows that you don't want to see; and (2) you could modify pathDiagram() -- the code for the function is, after all, available to you -- so that it does what you want. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox -- Dustin Fife Graduate Student, Quantitative Psychology University of Oklahoma __ 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. -- Dustin Fife Fife Photography www.fifephotography.com i...@fifephotography.com fife.dus...@gmail.com 405.414.5599 -- Dustin Fife Fife Photography www.fifephotography.com i...@fifephotography.com fife.dus...@gmail.com 405.414.5599 __ 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.diagram in SEM--display covariances without variances
For those who have the same question laterafter following John's steps of extracting the function, I just replaced the line of code that says: if ((!ignore.double) || (heads[par] == 1)) with if (((!ignore.double) || (heads[par] == 1)) variables[from[par]] != variables[to[par]]) That seems to do just what I want. Thanks again John! On Wed, Nov 9, 2011 at 5:40 PM, Dustin Fife fife.dus...@gmail.com wrote: Perfect! Thanks for the help. On Wed, Nov 9, 2011 at 4:27 PM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: Dustin Fife [mailto:fife.dus...@gmail.com] Sent: November-09-11 2:12 PM To: John Fox Cc: r-help@r-project.org Subject: Re: [R] path.diagram in SEM--display covariances without variances Thanks for the quick response...I've never edited someone else's package before. How do I go about doing that? I wouldn't change the sem package, but rather create your own version of pathDiagram(). You could examine the package sources, but, more simply, to see the code for the function, type its name at the command prompt: library(sem) Loading required package: MASS Loading required package: matrixcalc pathDiagram function (model, ...) { UseMethod(pathDiagram) } bytecode: 06E1CEA8 environment: namespace:sem So pathDiagram() is a generic function. What methods are available? methods(pathDiagram) [1] pathDiagram.sem* Non-visible functions are asterisked There is, therefore just one method, for objects of class sem, hidden in the sem namespace. To see it (most lines elided): sem:::pathDiagram.sem function (model, file, min.rank = NULL, max.rank = NULL, same.rank = NULL, variables = model$var.names, parameters = rownames(model$ram), ignore.double = TRUE, edge.labels = c(names, values, both), size = c(8, 8), node.font = c(Helvetica, 14), edge.font = c(Helvetica, 10), rank.direction = c(LR, TB), digits = 2, standardize = FALSE, output.type = c(graphics, dot), graphics.fmt = pdf, dot.options = NULL, ...) { . . . cat(file = handle, }\n) if (output.type == graphics !missing(file)) { cmd - paste(dot -T, graphics.fmt, -o , graph.file, , dot.options, , dot.file, sep = ) cat(Running , cmd, \n) result - try(system(cmd)) } invisible(NULL) } bytecode: 071B9568 environment: namespace:sem Just copy the functions into an editor and make whatever changes you want. Best, John On Wed, Nov 9, 2011 at 12:47 PM, John Fox j...@mcmaster.ca wrote: Dear Dustin, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dustin Fife Sent: November-09-11 10:57 AM To: r-help@r-project.org Subject: [R] path.diagram in SEM--display covariances without variances Forgive me if I'm posting to the wrong placeIt's my first time posting. Here's the situation: I'm using the sem package and making path diagrams using path.diagrams. Suppose I have the following code: . . . The diagram is produces is hard to read because of the many variances that are shown. The covariance estimates are important for my diagram, but the variances are not. Is there a way to suppress the variance arrows without suppressing the covariance arrows? No, but (1) pathDiagram() (the name of the function in the current version of the sem package) produces an editable text file, from which you could remove the arrows that you don't want to see; and (2) you could modify pathDiagram() -- the code for the function is, after all, available to you -- so that it does what you want. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox -- Dustin Fife Graduate Student, Quantitative Psychology University of Oklahoma __ 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.