Re: [R] Multiple plots with one legend
Yes that's what I had managed to generate too. I can produce my 3 plots. Each plot has 10 colored lines say. I want to place the legend in the 4th spot listing the name of the 10 colored lines, and their color. -- View this message in context: http://r.789695.n4.nabble.com/Multiple-plots-with-one-legend-tp3408537p3408850.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] Bootstrap 95% confidence intervals for splines
There appear to be reports in the literature that transform continuous independent variablea by the use of splines, e.g., assume the dependent variable is hot dogs eaten per week (HD) and the independent variable is waistline (WL), a normal linear regression model would be: nonconfusing_regression - lm(HD ~ WL) One might use a spline, confusion_inducing_regression_with_spline - lm(HD ~ ns(WL, df = 4) ) Now is where the problem starts. From nonconfusing_regression , I get, say 2 added hot dogs per week for each centimeter of waistline along with a s.e. of 0.5 hot dogs per week, which I multiply by 1.96 to garner each side of the 95% c.i. If I want to show what the difference between the 75th percentile (say 100 cm) and 25th percentile (say 80 cm) waistlines are, I multiply 2 by 100-80=20 and get 40 hot dogs per week as the point estimate with a similar bumping of the s.e. to 10 hot dogs per week. What do I do to get the point estimate and 95% confidence interval for the difference between 100 cm persons and 80 cm persons with confusion_inducing_regression_with_spline ? Best regards. Mitchell S. Wachtel, MD -- View this message in context: http://r.789695.n4.nabble.com/Bootstrap-95-confidence-intervals-for-splines-tp3408813p3408813.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] Garchoxfit package
Dear List, I'm now using Ubuntu 10.10 and I want to use the garchoxfit function.It seems that I need to download the package. While after installing the package,I still can't use the garchoxfit function.What's the reason and how to fix that? Thanks for your time! Best, Ning __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] run function on subsets of matrix
I was wondering if it is possible to do the following in a smarter way. I want get the mean value across the columns of a matrix, but I want to do this on subrows of the matrix, given by some vector(same length as the the number of rows). Something like nObs- 6 nDim - 4 m - matrix(rnorm(nObs*nDim),ncol=nDim) fac-sample(1:(nObs/2),nObs,rep=T) ##loop trough different 'factor' levels for (i in unique(fac)) print(apply(m[fac==i,],2,mean)) Now, the problem is that if a value in 'fac' only occurs once, the 'apply' function will complain. But I think, this can also be written more cleverly using some R style construct using factorlevels. 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] Garchoxfit package
On Mar 26, 2011, at 11:16 PM, Ning Cheng wrote: Dear List, I'm now using Ubuntu 10.10 and I want to use the garchoxfit function.It seems that I need to download the package. While after installing the package,I still can't use the garchoxfit function.What's the reason and how to fix that? A typical beginner error is to forget to also use either library() or require() to load an installed package. Installation only puts the files in the library. It does not load it into the workspace. You should in the future offer your session which will make comments more specific than this guessing game you have requested. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] run function on subsets of matrix
On Mar 26, 2011, at 10:26 PM, fisken wrote: I was wondering if it is possible to do the following in a smarter way. I want get the mean value across the columns of a matrix, but I want to do this on subrows of the matrix, given by some vector(same length as the the number of rows). Something like nObs- 6 nDim - 4 m - matrix(rnorm(nObs*nDim),ncol=nDim) fac-sample(1:(nObs/2),nObs,rep=T) ##loop trough different 'factor' levels for (i in unique(fac)) print(apply(m[fac==i,],2,mean)) This would be a lot simpler and faster: colMeans(m[unique(fac),]) #[1] 1.3595197 -0.1374411 0.1062527 -0.3897732 Now, the problem is that if a value in 'fac' only occurs once, the 'apply' function will complain. Because [ will drop single dimensions and so the matrix becomes a vector and looses the number-2 margin. Use drop=FALSE to prevent this, and note the extra comma: print(apply(m[1, , drop=FALSE],2,mean)) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] run function on subsets of matrix
On Mar 27, 2011, at 08:25 , David Winsemius wrote: On Mar 26, 2011, at 10:26 PM, fisken wrote: I was wondering if it is possible to do the following in a smarter way. I want get the mean value across the columns of a matrix, but I want _along_ the columns, I assume. to do this on subrows of the matrix, given by some vector(same length as the the number of rows). Something like nObs- 6 nDim - 4 m - matrix(rnorm(nObs*nDim),ncol=nDim) fac-sample(1:(nObs/2),nObs,rep=T) ##loop trough different 'factor' levels for (i in unique(fac)) print(apply(m[fac==i,],2,mean)) This would be a lot simpler and faster: colMeans(m[unique(fac),]) #[1] 1.3595197 -0.1374411 0.1062527 -0.3897732 Say what??? (I suspect David needs to get his sleep - or coffee, if he is in Europe.) How about: aggregate(m,list(fac),mean) Group.1 V1 V2 V3 V4 1 1 -0.03785420 -0.2573805 -0.3025759 0.00696 2 2 -1.39961300 0.2296900 -0.1122359 -0.302734531 3 3 0.50886649 0.6546153 -0.4270368 -0.411807709 by(m,list(fac),colMeans) : 1 V1 V2 V3 V4 -0.037854195 -0.257380542 -0.302575901 0.00696 - : 2 V1 V2 V3 V4 -1.3996130 0.2296900 -0.1122359 -0.3027345 - : 3 V1 V2 V3 V4 0.5088665 0.6546153 -0.4270368 -0.4118077 (whereas fac [1] 3 1 1 2 3 1 colMeans(m[unique(fac),]) [1] 0.39949029 -0.10989080 -0.96655778 0.01262903 colMeans(m[1:3,]) [1] 0.39949029 -0.10989080 -0.96655778 0.01262903 ) Now, the problem is that if a value in 'fac' only occurs once, the 'apply' function will complain. Because [ will drop single dimensions and so the matrix becomes a vector and looses the number-2 margin. Use drop=FALSE to prevent this, and note the extra comma: print(apply(m[1, , drop=FALSE],2,mean)) Yep. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hmisc summary.formula formats for binary and continuous variables
Hello, I am using Hmisc summary.formula, latex and Sweave to produce tables for publication. Is it possible to change the formats for binary and continuous variables? I would prefer to show 35 (10%) and 1.5 (1.2-1.8) rather than 10% (35) and 1.2 / 1.5 / 1.8. Here is a simple example: sex - factor(sample(c(m,f), 500, rep=TRUE)) age - rnorm(500, 50, 5) treatment - factor(sample(c(Drug,Placebo), 500, rep=TRUE)) s1 - summary(~sex + age) s2 - summary(treatment ~ sex + age, method=reverse) print(s1); print(s2) Descriptive Statistics (N=500) +---+-+ | | | +---+-+ |sex : m|46% (232)| +---+-+ |age|47.22/50.31/53.37| +---+-+ Descriptive Statistics by treatment +---+-+-+ | |Drug |Placebo | | |(N=257) |(N=243) | +---+-+-+ |sex : m|47% (122)|45% (110)| +---+-+-+ |age|47.35/50.00/52.68|46.78/50.92/53.97| +---+-+-+ Thanks, Heemun - Heemun Kwok, M.D. Research Fellow Harbor-UCLA Department of Emergency Medicine 1000 West Carson Street, Box 21 Torrance, CA 90509-2910 office 310-222-3501, fax 310-212-6101 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hmisc summary.formula formats for binary and continuous variables
I played around with this for awhile and did not get very far. I did not see any arguments in summary.formula or its print methods to reorder (happy to be corrected). Another approach I toyed with was to create a custom function to pass to summary.formula() that would itself create (something like) the desired output. foo - function(x) { n - length(x) pct - n/5 c(FOO = paste(n, (, round(pct, digits = 0), %), sep = '')) } summary(treatment ~ sex + age, fun = foo, method = response) treatmentN=500 +---+---+---+-+ | | |N |FOO | +---+---+---+-+ |sex|f |273|273(55%) | | |m |227|227(45%) | +---+---+---+-+ |age|[36.8,46.7)|125|125(25%) | | |[46.7,50.0)|125|125(25%) | | |[50.0,53.3)|125|125(25%) | | |[53.3,67.5]|125|125(25%) | +---+---+---+-+ |Overall| |500|500(100%)| +---+---+---+-+ However, it does not work with method = reverse. Also, this approach would seem to require either defining a very flexible function or multiple ones for each different situation you come across. Looking at print.summary.formula.reverse, the magic seems to happen on lines 47-50: cs - formatCats(stats[[i]], nam, tr, type[i], if (length(x$group.freq)) x$group.freq else x$n[i], npct, pctdig, exclude1, long, prtest, pdig = pdig, eps = eps) which lead me to explore formatCats(). A small tweak in the order of the paste() call on lines 25-33 (and creating a copy in of the altered version plus print.summary.formula.reverse in the global environment), got me: print.summary.formula.reverse(summary(treatment ~ sex + age, method=reverse)) Descriptive Statistics by treatment +---+--+--+ | |Drug |Placebo | | |(N=262) |(N=238) | +---+--+--+ |sex : m| (118) 45% | (114) 48% | +---+--+--+ |age|46.5/50.0/53.8|46.6/49.5/52.6| +---+--+--+ which has the percentage info on the right side, though I did not take the time to get the parentheses moved over. Still, it seems like adding an argument that just flipped the order might not take that much work/code. Cheers, Josh (Though I cannot help but wonder if in response to I want to cross the street I just said we could start building a two-lane, underground tunnel with and someone is probably going to come along and point out the cross walk 10 feet down the street) On Sat, Mar 26, 2011 at 11:09 PM, Kwok, Heemun hk...@emedharbor.edu wrote: Hello, I am using Hmisc summary.formula, latex and Sweave to produce tables for publication. Is it possible to change the formats for binary and continuous variables? I would prefer to show 35 (10%) and 1.5 (1.2-1.8) rather than 10% (35) and 1.2 / 1.5 / 1.8. Here is a simple example: sex - factor(sample(c(m,f), 500, rep=TRUE)) age - rnorm(500, 50, 5) treatment - factor(sample(c(Drug,Placebo), 500, rep=TRUE)) s1 - summary(~sex + age) s2 - summary(treatment ~ sex + age, method=reverse) print(s1); print(s2) Descriptive Statistics (N=500) +---+-+ | | | +---+-+ |sex : m| 46% (232) | +---+-+ |age |47.22/50.31/53.37| +---+-+ Descriptive Statistics by treatment +---+-+-+ | |Drug |Placebo | | |(N=257) |(N=243) | +---+-+-+ |sex : m| 47% (122) | 45% (110) | +---+-+-+ |age |47.35/50.00/52.68|46.78/50.92/53.97| +---+-+-+ Thanks, Heemun - Heemun Kwok, M.D. Research Fellow Harbor-UCLA Department of Emergency Medicine 1000 West Carson Street, Box 21 Torrance, CA 90509-2910 office 310-222-3501, fax 310-212-6101 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiple plots with one legend
Here is how to do the legend: x - cbind(rbind(1,2,3), 4) layout(x, width = c(5,1)) layout.show(4) plot(1:10, type = 'l') plot(1:10, type = 'l') plot(1:10, type = 'l') # reset margins for creating the legend oldMar - par(mar = c(0,0,0,0)) plot.new() legend('center' , legend = 1:10 , lwd = 3 , col = 1:10 ) par(oldMar) On Sun, Mar 27, 2011 at 12:43 AM, mavkoup mavk...@hotmail.com wrote: Yes that's what I had managed to generate too. I can produce my 3 plots. Each plot has 10 colored lines say. I want to place the legend in the 4th spot listing the name of the 10 colored lines, and their color. -- View this message in context: http://r.789695.n4.nabble.com/Multiple-plots-with-one-legend-tp3408537p3408850.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] run function on subsets of matrix
On Mar 27, 2011, at 3:22 AM, peter dalgaard wrote: On Mar 27, 2011, at 08:25 , David Winsemius wrote: On Mar 26, 2011, at 10:26 PM, fisken wrote: I was wondering if it is possible to do the following in a smarter way. I want get the mean value across the columns of a matrix, but I want _along_ the columns, I assume. to do this on subrows of the matrix, given by some vector(same length as the the number of rows). Something like nObs- 6 nDim - 4 m - matrix(rnorm(nObs*nDim),ncol=nDim) fac-sample(1:(nObs/2),nObs,rep=T) ##loop trough different 'factor' levels for (i in unique(fac)) print(apply(m[fac==i,],2,mean)) This would be a lot simpler and faster: colMeans(m[unique(fac),]) #[1] 1.3595197 -0.1374411 0.1062527 -0.3897732 Say what??? (I suspect David needs to get his sleep - or coffee, if he is in Europe.) At that point it was sleep that I needed. Now trying to decide if I should just go back to bed or make coffee. How about: aggregate(m,list(fac),mean) Group.1 V1 V2 V3 V4 1 1 -0.03785420 -0.2573805 -0.3025759 0.00696 2 2 -1.39961300 0.2296900 -0.1122359 -0.302734531 3 3 0.50886649 0.6546153 -0.4270368 -0.411807709 by(m,list(fac),colMeans) : 1 V1 V2 V3 V4 -0.037854195 -0.257380542 -0.302575901 0.00696 - : 2 V1 V2 V3 V4 -1.3996130 0.2296900 -0.1122359 -0.3027345 - : 3 V1 V2 V3 V4 0.5088665 0.6546153 -0.4270368 -0.4118077 -- Peter Dalgaard David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] A question on glmnet analysis
(11/03/25 22:40), Nick Sabbe wrote: 2. Which model, I mean lasso or elastic net, should be selected? and why? Both models chose the same variables but different coefficient values. You may want to read 'the elements of statistical learning' to find some info on the advantages of ridge/lasso/elnet compared. Lasso should work fine in this relatively low-dimensional setting, although it depends on the correlation structure of your covariates. I also checked correlation structure of my covariates. test - lm(y ~ x15std) library(DAAG) vif(test) x15std1 x15std2 x15std3 x15std4 x15std5 x15std6 x15std7 x15std8 x15std9 x15std10 x15std11 x15std12 x15std13 x15std14 1.2299 1.2880 1.1011 1.1559 1.3033 1.0774 1.5369 1.9604 1.4664 1.1754 1.1396 1.2683 1.1685 1.1667 x15std15 1.5534 Variance inflation are less than 5 suggesting that multicollinearity is unlikely to be a problem. Therefore, Lasso model should be selected? Thanks a lot in advance, KH __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] About proportional odds ratio model with LASSO in ordinal regression
If you can work with a different penalty check out the lrm function from the rms package, which uses penalized likelihood to fit proportional odds. 2011/3/24 Jheng-Jhong Wang iiamba...@gmail.com: Dear R-users, I try to fit proportional odds ratio model with LASSO in ordinal regression. But I just find as below: glmnet package which used in Binomail and Multinomail response. glmnetcr package which used in contiuation-Ratio Logits model. Does someone know a package and/or function on R to do proportional odds ratio model with LASSO together? Thanks. --- Jheng Jhong Wang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] model diagnostics for MatrixModels
Dear list, I have been working with the MatrixModels package quite a bit this week, and it is proving to be extremely valuable for my current work (I am working with several factors with many levels, leading to a sparse model matrix). However, as my knowledge of statistical theory leaves much to be desired, there are certain aspects of model evaluation etc that I am having trouble with. Has anyone developed any examples of model diagnostics using the glpModel class (from the MatrixModels package)? Something akin to 'summary', or perhaps helper functions such as 'logLik', 'AIC', 'predict' or even a means of running some of the tests from package 'lmtest'? The structure of the 'glpModel' class is pretty straight-forward, so I am able to extract *some* of the relevant information to perform *some* of these tests myself, however, an example of performing some 'standard' model diagnostics or tests/comparisons would be very helpful (In this case I am really only interested in tests etc relevant to GLMs). I'm not against writing some of these functions myself, so any tips/suggestions/resources/examples are appreciated. Furthermore, does anyone know if there facilities to obtain, for example, the rank of the (sparse) model matrix efficiently? Quite a few tests require rank, but computing this separately using for example rankMatrix from package Matrix uses up tonnes of memory, which is exactly what I was trying to avoid by using sparse matrices and glm4 :-p Thanks for any pointers, Carson sessionInfo() R version 2.12.2 (2011-02-25) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_IE.utf8 LC_NUMERIC=C [3] LC_TIME=en_IE.utf8LC_COLLATE=en_IE.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_IE.utf8 [7] LC_PAPER=en_IE.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_IE.utf8 LC_IDENTIFICATION=C attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] MatrixModels_0.2-1 pscl_1.03.6gam_1.03 akima_0.5-4 [5] coda_0.13-5mvtnorm_0.9-92 lmtest_0.9-27 zoo_1.6-4 [9] Matrix_0.999375-48 lattice_0.19-17MASS_7.3-7 loaded via a namespace (and not attached): [1] grid_2.12.2 tools_2.12.2 -- Carson J. Q. Farmer ISSP Doctoral Fellow National Centre for Geocomputation National University of Ireland, Maynooth, http://www.carsonfarmer.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.
Re: [R] line graph question
?axis Sent from my iPad On Mar 26, 2011, at 18:21, Bulent Arikan bulent.ari...@gmail.com wrote: Hi, I am working on some line charts and although I have a lot of resources, I cannot seem to find an answer to this question: how can I set the incrementation of values on the x-axis values so that I can see all the groups on this axis. Right now, R puts them at increments of 2 (i.e., 2, 4, 6, 8, 10, 12). I need to see all, from 1 to 12. Thank you! -- BÜLENT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bootstrap 95% confidence intervals for splines
You're mixing up two concepts here, - splines - bootstrap confidence intervals Separating them may help cut the confusion. First, to do a bootstrap confidence interval for a difference in predictions in the linear regression case, do: repeat 10^4 times draw a bootstrap sample of the observations (subjects, keeping x y together) fit the linear regression to the bootstrap sample record the difference in predictions at the two x values end loop The bootstrap confidence interval is the range of the middle 95% of the recorded differences. For a spline, the procedure is the same except for fitting a spline regression: repeat 10^4 times draw a bootstrap sample of the observations (subjects, keeping x y together) fit the SPLINE regression to the bootstrap sample record the difference in predictions at the two x values end loop The bootstrap confidence interval is the range of the middle 95% of the recorded differences. Tim Hesterberg P.S. I think you're mixing up the response and explanatory variables. I'd think of eating hot dogs as the cause (explanatory variable), and waistline as the effect (response, or outcome). P.P.S. I don't like the terms independent and dependent variables, as that conflicts with the concept of independence in probability. Independent variables are generally not independent, and the dependent variable may be independent of the others. There appear to be reports in the literature that transform continuous independent variablea by the use of splines, e.g., assume the dependent variable is hot dogs eaten per week (HD) and the independent variable is waistline (WL), a normal linear regression model would be: nonconfusing_regression - lm(HD ~ WL) One might use a spline, confusion_inducing_regression_with_spline - lm(HD ~ ns(WL, df = 4) ) Now is where the problem starts. From nonconfusing_regression , I get, say 2 added hot dogs per week for each centimeter of waistline along with a s.e. of 0.5 hot dogs per week, which I multiply by 1.96 to garner each side of the 95% c.i. If I want to show what the difference between the 75th percentile (say 100 cm) and 25th percentile (say 80 cm) waistlines are, I multiply 2 by 100-80=20 and get 40 hot dogs per week as the point estimate with a similar bumping of the s.e. to 10 hot dogs per week. What do I do to get the point estimate and 95% confidence interval for the difference between 100 cm persons and 80 cm persons with confusion_inducing_regression_with_spline ? Best regards. Mitchell S. Wachtel, MD __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] bwplot [lattice]: how to get different y-axis scales for each row?
Dear expeRts, I partially managed to obtain what I wanted by using latticeExtra. However, the following questions remain: 1) why do not all x-axis labels appear? [compare bw and bw2] 2) Can I have the y-axis labels on the right margin/side of the plot? Changing the alternating argument does not do the job since relation=free Cheers, Marius library(lattice) library(latticeExtra) ## build example data set dim - c(100, 6, 4, 3) # n, groups, methods, attributes dimnames - list(n=paste(n=, seq_len(100), sep=), groups=paste(group=, seq_len(6), sep=), methods=paste(method=, seq_len(4), sep=), attr=paste(attribute=, seq_len(3), sep=)) set.seed(1) data - rexp(prod(dim)) arr - array(data=data, dim=dim, dimnames=dimnames) arr[,2,,] - arr[,2,,]*10 arr[,4,2,2] - arr[,4,2,2]*10 z - abs(sweep(arr, 3, 1)) df - as.data.frame.table(z, responseName=error) ## box plot bw - bwplot(error ~ methods | attr * groups, data=df, as.table=TRUE, notch=TRUE, scales=list(y=list(alternating=c(1,1), tck=c(1,0)), relation=free)) (bw2 - useOuterStrips(combineLimits(bw, extend=FALSE On 2011-03-26, at 09:34 , Marius Hofert wrote: Dear expeRts, How can I get ... (1) different y-axis scales for each row (2) while having the same y-axis scales for different columns? I coulnd't manage to do this with relation=free [which gives (1) but not (2)]. I also tried relation=sliced, but it did not give the same y-axis scales within each row (see the fourth row). Further, it separates the panels. Cheers, Marius ## minimal example: library(lattice) ## build example data set dim - c(100, 6, 2, 3) # n, groups, methods, attributes dimnames - list(n=paste(n=, seq_len(100), sep=), groups=paste(group=, seq_len(6), sep=), methods=paste(method=, seq_len(2), sep=), attr=paste(attribute=, seq_len(3), sep=)) set.seed(1) data - rexp(prod(dim)) arr - array(data=data, dim=dim, dimnames=dimnames) arr[,2,,] - arr[,2,,]*10 arr[,4,2,2] - arr[,4,2,2]*10 z - abs(sweep(arr, 3, 1)) df - as.data.frame.table(z, responseName=error) ## box plot bwplot(error ~ methods | attr * groups, data=df, as.table=TRUE, notch=TRUE, scales=list(alternating=c(1,1), tck=c(1,0))) ## with relation=sliced bwplot(error ~ methods | attr * groups, data=df, as.table=TRUE, notch=TRUE, scales=list(alternating=c(1,1), tck=c(1,0), relation=sliced)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] (no subject)
http://dix4life.leadhoster.com/molo.php [[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] Asking Favor For the Script of Median Filter
Hello,everybody. My name is Chuan Zun Liang. I come from Malaysia. I am just a beginner for R. Kindly to ask favor about median filter. The problem I facing as below: x-matrix(sample(1:30,25),5,5) x [,1] [,2] [,3] [,4] [,5] [1,]78 30 29 13 [2,]46 1259 [3,] 253 22 14 24 [4,]2 15 26 23 19 [5,] 28 18 10 11 20 This is example original matrices of an image. I want apply with median filter with window size 3X# to remove salt and pepper noise in my matric. Here are the script I attend to writing.The script and output shown as below: MedFilter-function(mat,sz) + {out-matrix(0,nrow(mat),ncol(mat)) + for(p in 1:(nrow(mat)-(sz-1))) + {for(q in 1:(ncol(mat)-(sz-1))) + {outrow-median(as.vector(mat[p:(p+(sz-1)),q:(q+(sz-1))])) + out[(p+p+(sz-1))/2,(q+q+(sz-1))/2]-outrow}} + out} MedFilter(x,3) [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]08 12 140 [3,]0 12 14 190 [4,]0 18 15 200 [5,]00000 Example to getting value 8 and 12 as below: 7 8 30 8 30 29 4 6 12 (median=8) 6 12 5 (median=12) 25 3 22 3 22 14 Even the script can give output. However, it is too slow. My image size is 364*364. It is time consumption. Is it get other ways to improving it? Best Wishes Chuan -- View this message in context: http://r.789695.n4.nabble.com/Asking-Favor-For-the-Script-of-Median-Filter-tp3409462p3409462.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] Problem with R, MKL, and Ubuntu 11.04
This may not be a proper question to ask here, however I don't find a better place to ask. I am testing Ubuntu Natty 11.04. I build R with Blas/Lapack linked to intel MKL. Everything works fine but when quitting R with q(), the R process won't quit, and the system monitor shows its waiting channel as futex_wait_queue_me. For example, with make check, the process will halted after checking the graphics package, whose test script called lm(), which I think used lapack routines in MKL. The next thing I tried is using environmental variables such that MKL runs in sequential mode. Then everything goes perfect. make check was successful. So I identified that the problem is with the multi-threaded version of MKL. After some trials, I think it is true, as eigen(), inv(), and matrix multiplication, etc all cause the same problem. The computing itself is fine, but R is halted when quiting. Then I wrote some C code using blas/lapack to test, and there's no problem with MKL, at least with my testing code. Both R-2.13 and R-2.12 are tried. Both intel icc and gcc, ifort and gfortran are tried. In sum, I tried most configuration combination of compilers, openmp flags, etc I can think about. But the problem persist. I think this could be a problem with ubuntu 11.04. So this as I said in the beginning, this may not be a proper question to ask here. However, I tried blas/lapack routines for decomposition, etc in C, and it runs without problem. So there's may be some workaround with the problem when building R and hopefully someone can give some hints. Best, Yan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] gtk, RGtk2 and error in callback: delet_event in mai window
Hello All, I am trying to learn about the GUI in R (with GTK+Glade+RGtk2) and in my test I don't get sucess in to make an callback to destroy the application... When I try to define an function for delet-event callback, I get the error message: (with mouse click in X window) *Error in function () : * * unused argument(s) (pointer: 0x017ca000, pointer: 0x017db218)* So, somebody has a tips for me? Thanks in advanded Cleber # make a file GLADE for testing... tmp - textConnection(' + ?xml version=1.0? + interface + requires lib=gtk+ version=2.16/ + !-- interface-naming-policy project-wide -- + object class=GtkWindow id=window1 + signal name=delete_event handler=window1_delete_event/ + child + placeholder/ + /child + /object + /interface + ') glade_file - readLines( tmp ) close( tmp ); rm( tmp ) sink( file='glade_file.txt') cat( glade_file ) sink() # call the binfings for GTK ( RGtk2_2.20.8 ) library(RGtk2) *Warning message:* *In inDL(x, as.logical(local), as.logical(now), ...) :* * DLL attempted to change FPU control word from 8001f to 9001f* GUI - gtkBuilderNew() res - gtkBuilderAddFromFile( GUI, filename='glade_file.txt' ) unlink( 'glade_file.txt' ) # callback from delete_event ( small X in the Window ) window1_delete_event - function() print('Work or dont work???') gtkBuilderConnectSignals( GUI ) window_main - gtkBuilderGetObject( GUI, 'window1') gtkWidgetShowAll( window_main ) # # # # with the mouse, click in X window to close!! # # # *Error in function () : * * unused argument(s) (pointer: 0x017ca000, pointer: 0x017db218)* # sessionInfo() R version 2.12.2 (2011-02-25) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RGtk2_2.20.8 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R Help
Hi, Creating the X'y vector has been troublesome. I get the error: requires numeric/complex matrix/vector arguments. Could you please look at my code and tell me what I am doing wrong? I have several dummy variables among my independent variables. #Variable MHL16, or that corresponding to whether the school social worker is required to be licensed or certified by a state agency or board, is coded as dependent variable y1 - subset(dat, select=c(MHL16)) y - as.matrix(y1[1:873,]) summary(y) y #Create independent variable vectors x02 - subset(dat, select=c(sampstra)) x03 - subset(dat, select=c(size)) x03.dummy - subset(x03==2) #where True=large size and False=small size dim(x03.dummy) x04 - subset(dat, select=c(level)) x05 - subset(dat, select=c(ENROLL)) x06 - subset(dat, select=c(URBAN)) x06.dummy - subset(x06==1) #where True=urban and False=non-urban or NA x07 - subset(dat, select=c(REGION)) x08 - subset(dat, select=c(POVERTY)) x08.dummy - subset(x08==2) #where True=high poverty and False=low proverty or NA x08.dummy dim(x08.dummy) x09 - subset(dat, select=c(MHL12)) #is there a PT/FT school social worker who provides mental health/social services to students x09.dummy - subset(x09==1) #where True=yes and False=no dim(x09.dummy) x010 - subset(dat, select=c(MHL13)) #how many PT/FT school social workers provides services x011 - subset(dat, select=c(MHL15)) #what is the minimum level of education required for newly hired school social worker x012 - subset(dat, select=c(MHL27c_03)) #does the school social worker provide services for pregnancy prevention x012.dummy - subset(x012==1) #where True=yes, False=no x013 - subset(dat, select=c(MHL27d_03)) #does the school social worker provide services for HIV prevention x013.dummy - subset(x013==1) #where True=yes, False=no x2 - as.matrix(x02[1:843,]) x3 - as.matrix(x03.dummy[1:843,]) x4 - as.matrix(x04[1:843,]) x5 - as.matrix(x05[1:843,]) x6 - as.matrix(x06.dummy[1:843,]) x7 - as.matrix(x07[1:843,]) x8 - as.matrix(x08.dummy[1:843,]) x9 - as.matrix(x09.dummy[1:843,]) x10 - as.matrix(x010[1:843,]) x11 - as.matrix(x011[1:843,]) x12 - as.matrix(x012.dummy[1:843,]) x13 - as.matrix(x013.dummy[1:843,]) #Create X matrix X - cbind(1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13) dim(X) Xty - t(X)%*%y Error in t(X) %*% y : requires numeric/complex matrix/vector arguments 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 labeling Panels
Hi, I'm new. I tried to search out this answer but I suspect I was using the wrong terms, or simply not understanding some of the answers. Anyway here is my question: I want to have a 2x2 panel figure with 4 line graphs all in the same scale. Actually I have that. The thing I seem to be lacking is a way to Label each panel with a letter. I want it to look something like this: http://www.nature.com/npp/journal/v31/n9/images/1301015f3.gif I am using linux and I'm not even entirely sure if I've done this in a best practices sort of way but here is the code that I've entered so far to make my figure: library(sciplot) postscript('PreferenceGraph2x2.eps') par(mfrow = c(2,2), pin=c(6.45669292,6.45669292), pty=m) lineplot.CI(Week, Pref, group = Drug, data=SM.long, xlab = Week, ylab =Proportion Sucrose of Total Fluids, x.leg =1, y.leg=.91, leg.lab= c(Salvia,Control),col =c(red,darkgreen),ylim=c(0.48,.95), main = Preference of Stressed Males) lineplot.CI(Week, Pref, group = Drug, data=SF.long, xlab = Week, ylab =Proportion Sucrose of Total Fluids, x.leg =1, y.leg=.60, leg.lab= c(Salvia,Control),col =c(red,darkgreen),ylim=c(0.48,.95), main = Preference of Stressed Females) lineplot.CI(Week, Pref, group = Drug, data=NSM.long, xlab = Week, ylab =Proportion Sucrose of Total Fluids, x.leg =1, y.leg=.64, leg.lab= c(Salvia,Control),col =c(red,darkgreen),ylim=c(0.48,.95), main = Preference of Non-Stressed Males) lineplot.CI(Week, Pref, group = Drug, data=NSF.long, xlab = Week, ylab =Proportion Sucrose of Total Fluids, x.leg =1, y.leg=.64, leg.lab= c(Salvia,Control),col =c(red,darkgreen),ylim=c(0.48,.95), main = Preference of Non-Stressed Females) dev.off() Thanks in advanced for any help you might give! -- View this message in context: http://r.789695.n4.nabble.com/Help-labeling-Panels-tp3409528p3409528.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] pmt
I am working with the pmt function in the {mnormt} package, and i am getting negative values returned. the following is an example of one of my outputs: pmt(x = c(3.024960, -1.010898), mean = c(21.18844, 21.18844), S = matrix(c(.319,.139,.139,0.319), 2, 2),df = 42) # -6.585641e-18 Any help on why i'm getting negative numbers would be very much appreciated. THanks! -- View this message in context: http://r.789695.n4.nabble.com/pmt-tp3409543p3409543.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] Sweave: include a multi-page-pdf plot
Hi, I'm just starting out with Sweave, and I can't get a plot(linmod) to display all four plots: bild = x1 - runif(100) x2 - rexp(100) y - 3 + 4*x1 + 5*x2 + rnorm(100) mod - lm(y~x1+x2) plot(mod) @ Some Text fig=TRUE= bild @ This plots only the first image of the four-page plot.lm() result. I don't want to use par(mfrow=c(2,2)), but ideally I'd like to access each one of the four plots in a different section of my LaTeX-file. Can you tell me how to do this? Thanks in advance, Alex __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Hmisc summary.formula formats for binary and continuous variables
If by 35 (10%) you mean that 35 is the numerator, this is not such a good idea. That's because it emphasizes something that is not a scientific quantity. A scientific quantity is something that has a meaning outside the current sample. The numerator is dependent on the denominator. Regarding the other formatting issue, summary.formula with method='reverse' is not flexible enough to allow that. Frank Kwok, Heemun wrote: Hello, I am using Hmisc summary.formula, latex and Sweave to produce tables for publication. Is it possible to change the formats for binary and continuous variables? I would prefer to show 35 (10%) and 1.5 (1.2-1.8) rather than 10% (35) and 1.2 / 1.5 / 1.8. Here is a simple example: sex lt;- factor(sample(c(quot;mquot;,quot;fquot;), 500, rep=TRUE)) age lt;- rnorm(500, 50, 5) treatment lt;- factor(sample(c(quot;Drugquot;,quot;Placeboquot;), 500, rep=TRUE)) s1 lt;- summary(~sex + age) s2 lt;- summary(treatment ~ sex + age, method=quot;reversequot;) print(s1); print(s2) Descriptive Statistics (N=500) +---+-+ | | | +---+-+ |sex : m|46% (232)| +---+-+ |age|47.22/50.31/53.37| +---+-+ Descriptive Statistics by treatment +---+-+-+ | |Drug |Placebo | | |(N=257) |(N=243) | +---+-+-+ |sex : m|47% (122)|45% (110)| +---+-+-+ |age|47.35/50.00/52.68|46.78/50.92/53.97| +---+-+-+ Thanks, Heemun - Heemun Kwok, M.D. Research Fellow Harbor-UCLA Department of Emergency Medicine 1000 West Carson Street, Box 21 Torrance, CA 90509-2910 office 310-222-3501, fax 310-212-6101 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Hmisc-summary-formula-formats-for-binary-and-continuous-variables-tp3408967p3409563.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.
Re: [R] Asking Favor For the Script of Median Filter
( sorry if this is a duplicate, I am not sure if hotmail is dropping some of my posts. Thanks ) You obviously want to delegate inner loops to R packages that execute as native, hopefully optimized, code. Generally a google search that starts with R CRAN will help. In this case it looks like a few packages available, http://www.google.com/search?sclient=psyhl=enq=R+cran+median+filter Date: Sun, 27 Mar 2011 07:56:11 -0700 From: chuan...@hotmail.com To: r-help@r-project.org Subject: [R] Asking Favor For the Script of Median Filter Hello,everybody. My name is Chuan Zun Liang. I come from Malaysia. I am just a beginner for R. Kindly to ask favor about median filter. The problem I facing as below: x-matrix(sample(1:30,25),5,5) x [,1] [,2] [,3] [,4] [,5] [1,] 7 8 30 29 13 [2,] 4 6 12 5 9 [3,] 25 3 22 14 24 [4,] 2 15 26 23 19 [5,] 28 18 10 11 20 This is example original matrices of an image. I want apply with median filter with window size 3X# to remove salt and pepper noise in my matric. Here are the script I attend to writing.The script and output shown as below: MedFilter-function(mat,sz) + {out-matrix(0,nrow(mat),ncol(mat)) + for(p in 1:(nrow(mat)-(sz-1))) + {for(q in 1:(ncol(mat)-(sz-1))) + {outrow-median(as.vector(mat[p:(p+(sz-1)),q:(q+(sz-1))])) + out[(p+p+(sz-1))/2,(q+q+(sz-1))/2]-outrow}} + out} MedFilter(x,3) [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 8 12 14 0 [3,] 0 12 14 19 0 [4,] 0 18 15 20 0 [5,] 0 0 0 0 0 Example to getting value 8 and 12 as below: 7 8 30 8 30 29 4 6 12 (median=8) 6 12 5 (median=12) 25 3 22 3 22 14 Even the script can give output. However, it is too slow. My image size is 364*364. It is time consumption. Is it get other ways to improving it? Best Wishes Chuan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Help
Hi Anita, A bit of sample data would probably help here. Have a look at ?dput for a handy way to supply some data. Also a quick summary of exactly what you are trying to accomplish would be useful. A very cursory reading of the program leaves one wondering why you are creating all those variables, expecially the dummies. --- On Sun, 3/27/11, Yadavalli, Anita P ayada...@purdue.edu wrote: From: Yadavalli, Anita P ayada...@purdue.edu Subject: [R] R Help To: r-help@r-project.org r-help@r-project.org Received: Sunday, March 27, 2011, 12:23 PM Hi, Creating the X'y vector has been troublesome. I get the error: requires numeric/complex matrix/vector arguments. Could you please look at my code and tell me what I am doing wrong? I have several dummy variables among my independent variables. #Variable MHL16, or that corresponding to whether the school social worker is required to be licensed or certified by a state agency or board, is coded as dependent variable y1 - subset(dat, select=c(MHL16)) y - as.matrix(y1[1:873,]) summary(y) y #Create independent variable vectors x02 - subset(dat, select=c(sampstra)) x03 - subset(dat, select=c(size)) x03.dummy - subset(x03==2) #where True=large size and False=small size dim(x03.dummy) x04 - subset(dat, select=c(level)) x05 - subset(dat, select=c(ENROLL)) x06 - subset(dat, select=c(URBAN)) x06.dummy - subset(x06==1) #where True=urban and False=non-urban or NA x07 - subset(dat, select=c(REGION)) x08 - subset(dat, select=c(POVERTY)) x08.dummy - subset(x08==2) #where True=high poverty and False=low proverty or NA x08.dummy dim(x08.dummy) x09 - subset(dat, select=c(MHL12)) #is there a PT/FT school social worker who provides mental health/social services to students x09.dummy - subset(x09==1) #where True=yes and False=no dim(x09.dummy) x010 - subset(dat, select=c(MHL13)) #how many PT/FT school social workers provides services x011 - subset(dat, select=c(MHL15)) #what is the minimum level of education required for newly hired school social worker x012 - subset(dat, select=c(MHL27c_03)) #does the school social worker provide services for pregnancy prevention x012.dummy - subset(x012==1) #where True=yes, False=no x013 - subset(dat, select=c(MHL27d_03)) #does the school social worker provide services for HIV prevention x013.dummy - subset(x013==1) #where True=yes, False=no x2 - as.matrix(x02[1:843,]) x3 - as.matrix(x03.dummy[1:843,]) x4 - as.matrix(x04[1:843,]) x5 - as.matrix(x05[1:843,]) x6 - as.matrix(x06.dummy[1:843,]) x7 - as.matrix(x07[1:843,]) x8 - as.matrix(x08.dummy[1:843,]) x9 - as.matrix(x09.dummy[1:843,]) x10 - as.matrix(x010[1:843,]) x11 - as.matrix(x011[1:843,]) x12 - as.matrix(x012.dummy[1:843,]) x13 - as.matrix(x013.dummy[1:843,]) #Create X matrix X - cbind(1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13) dim(X) Xty - t(X)%*%y Error in t(X) %*% y : requires numeric/complex matrix/vector arguments 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] pmt
That is essentially zero, because you are so far out in the left tail of the distribution. So, you can ignore the negative sign and treat it as zero. Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: statfan irene_vr...@hotmail.com Date: Sunday, March 27, 2011 1:06 pm Subject: [R] pmt To: r-help@r-project.org I am working with the pmt function in the {mnormt} package, and i am getting negative values returned. the following is an example of one of my outputs: pmt(x = c(3.024960, -1.010898), mean = c(21.18844, 21.18844), S = matrix(c(.319,.139,.139,0.319), 2, 2),df = 42) # -6.585641e-18 Any help on why i'm getting negative numbers would be very much appreciated. THanks! -- View this message in context: Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave: include a multi-page-pdf plot
On 27/03/2011 1:12 PM, Alexander Engelhardt wrote: Hi, I'm just starting out with Sweave, and I can't get a plot(linmod) to display all four plots: bild= x1- runif(100) x2- rexp(100) y- 3 + 4*x1 + 5*x2 + rnorm(100) mod- lm(y~x1+x2) plot(mod) @ Some Text fig=TRUE= bild @ This plots only the first image of the four-page plot.lm() result. I don't want to use par(mfrow=c(2,2)), but ideally I'd like to access each one of the four plots in a different section of my LaTeX-file. Can you tell me how to do this? If you want 4 separate pages, you need 4 separate plots. You should change your code from plot(mod) to plot(mod, which=1), and then have 3 more code chunks containing plot(mod, which=n) where n is a number from 2 to 6. (The default is to use 2, 3, and 5.) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] export data to gnuplot
Hello How to export data frame to file which can be used by gnuplot? P.S. Sorry for naive question __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] grImport/ghostscript problems
Hi All: I've been struggling for a while trying to get grImport up and running. I'm on a Windows 7 (home premium 64 bit) machine running R-2.12.2 along with GPL Ghostscript 9.01. I've set my Windows PATH variable to point to the Ghostscript \bin and \lib directories, and I've created the R_GSCMD environment variable pointing to gswin32c.exe. I don't have any experience with Ghostscript, but with the setup described above I can view the postscript file with the following command to the Windows command prompt: gswin32c.exe D:\Sndbx\vasarely.ps However, I can't get the PostScriptTrace() function to work on the same file. Submitting PostScriptTrace(D:/Sndbx/vasarely.ps) gives me the error: Error in PostScriptTrace(D:/Sndbx/vasarely.ps) : status 127 in running command 'gswin32c.exe -q -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=C:\Users\Al\AppData\Local\Temp\RtmppPjDAf\file5db99cb -sstdout=vasarely.ps.xml capturevasarely.ps' Your suggestions are much appreciated. Cheers, Al [[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] grImport/ghostscript problems
Hi On 28/03/2011 8:13 a.m., Al Roark wrote: Hi All: I've been struggling for a while trying to get grImport up and running. I'm on a Windows 7 (home premium 64 bit) machine running R-2.12.2 along with GPL Ghostscript 9.01. I've set my Windows PATH variable to point to the Ghostscript \bin and \lib directories, and I've created the R_GSCMD environment variable pointing to gswin32c.exe. I don't have any experience with Ghostscript, but with the setup described above I can view the postscript file with the following command to the Windows command prompt: gswin32c.exe D:\Sndbx\vasarely.ps However, I can't get the PostScriptTrace() function to work on the same file. Submitting PostScriptTrace(D:/Sndbx/vasarely.ps) gives me the error: Error in PostScriptTrace(D:/Sndbx/vasarely.ps) : status 127 in running command 'gswin32c.exe -q -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=C:\Users\Al\AppData\Local\Temp\RtmppPjDAf\file5db99cb -sstdout=vasarely.ps.xml capturevasarely.ps' Your suggestions are much appreciated. Cheers, Al [[alternative HTML version deleted]] You could try running the ghostscript command that is printed in the error message at the Windows command prompt to see more info about the problem (might need to remove the '-q' so that ghostscript prints messages to the screen). Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] grImport/ghostscript problems
Paul Murrell p.murrell at auckland.ac.nz writes: Hi On 28/03/2011 8:13 a.m., Al Roark wrote: Hi All: I've been struggling for a while trying to get grImport up and running. I'm on a Windows 7 (home premium 64 bit) machine running R-2.12.2 along with GPL Ghostscript 9.01. I've set my Windows PATH variable to point to the Ghostscript \bin and \lib directories, and I've created the R_GSCMD environment variable pointing to gswin32c.exe. I don't have any experience with Ghostscript, but with the setup described above I can view the postscript file with the following command to the Windows command prompt: gswin32c.exe D:\Sndbx\vasarely.ps However, I can't get the PostScriptTrace() function to work on the same file. Submitting PostScriptTrace(D:/Sndbx/vasarely.ps) gives me the error: Error in PostScriptTrace(D:/Sndbx/vasarely.ps) : status 127 in running command 'gswin32c.exe -q -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=C:\Users\Al\AppData\Local\Temp\RtmppPjDAf\file5db99cb -sstdout=vasarely.ps.xml capturevasarely.ps' Your suggestions are much appreciated. Cheers, Al [[alternative HTML version deleted]] You could try running the ghostscript command that is printed in the error message at the Windows command prompt to see more info about the problem (might need to remove the '-q' so that ghostscript prints messages to the screen). Paul Thanks for your reply. Perhaps this is a Ghostscript problem. When I run the Ghostscript command, I'm met with the rather unhelpful error: 'GPL Ghostscript 9.01: Unrecoverable error, exit code 1 (occurs whether or not I remove the -q)'. Interestingly, if I remove the final argument (in this case, capturevasarely.ps) the Ghostscript command executes, placing a file (appears to be xml) in the temporary directory. However, I'm not sure what to do with this result. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] export data to gnuplot
On Sun, Mar 27, 2011 at 10:12:38PM +0300, Denis Kazakiewicz wrote: Hello How to export data frame to file which can be used by gnuplot? Hello: Try the following write.table(dat, file=out.txt, row.names=FALSE, col.names=FALSE, quote=FALSE) This will save a space delimited file. I am not using gnuplot for a long time, but i think a space delimited file can be used. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] World plots and clipping regions
Not with the code as it is provided. However with a reasonably easy modification to map.grid() (to return the coordinates of the red dotted line) and a call to polygon(), what you want can be achieved. Let me know if you need further details. Ray Brownrigg On 03/26/11 10:11, Saptarshi Guha wrote: Hello, Given the following display library(maps) library(mapproj) m - map('world',plot=FALSE) map('world',proj='mollweide',bg=bgcolor[2],col='white') map.grid(col=2,lim=c(-175,-175,-180,180),label=FALSE,lty=2) Is there a way to color the region outside the dotted red border? Thank you Saptarshi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function to compare Brier scores from two models?
Hi, I have probability estimates from two predictive models. I have these estimates and also a binary outcome for a validation data set not used in calibrating either model. I would like to calculate the Brier score for both models on this binary outcome and test the hypothesis that the Brier scores are equal from the two models. I have not been able to find an R function to do this, can someone point me to the appropriate library and function if one exists? Thanks, Seth -- View this message in context: http://r.789695.n4.nabble.com/function-to-compare-Brier-scores-from-two-models-tp3409714p3409714.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] comparing heatmaps
Dear all, I've been trying to find how to compare tow different heatmaps but I'm having trouble getting the colors bar to be the same. I'm doing something like the following: library(gplots) dat-cor(matrix(rnorm(100, m=10), nrow=10)) mat-cor(matrix(rnorm(100), nrow=10)) dev.new() heatmap.2(mat, Rowv=NA, Colv=NA, col=redgreen(75), symm=TRUE, trace=none, dendrogram=none, main = paste(Correlation Matrix for time delay at , sep=)) dev.new() heatmap.2(dat, Rowv=NA, Colv=NA, col=redgreen(75), symm=TRUE, trace=none, dendrogram=none, main = paste(Correlation Matrix for time delay at , sep=)) You'll probably notice that the color bar at the top left isn't the same scale. How do I do this? Thanks, Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function to compare Brier scores from two models?
Hi: Try library(sos) # install first if necessary findFn('Brier score') The first place I would look is Frank Harrell's rms package. HTH, Dennis On Sun, Mar 27, 2011 at 1:50 PM, Seth sjmy...@syr.edu wrote: Hi, I have probability estimates from two predictive models. I have these estimates and also a binary outcome for a validation data set not used in calibrating either model. I would like to calculate the Brier score for both models on this binary outcome and test the hypothesis that the Brier scores are equal from the two models. I have not been able to find an R function to do this, can someone point me to the appropriate library and function if one exists? Thanks, Seth -- View this message in context: http://r.789695.n4.nabble.com/function-to-compare-Brier-scores-from-two-models-tp3409714p3409714.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. [[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] export data to gnuplot
Dear Petr Thank you very much У Няд, 27/03/2011 у 22:23 +0200, Petr Savicky піша: On Sun, Mar 27, 2011 at 10:12:38PM +0300, Denis Kazakiewicz wrote: Hello How to export data frame to file which can be used by gnuplot? Hello: Try the following write.table(dat, file=out.txt, row.names=FALSE, col.names=FALSE, quote=FALSE) This will save a space delimited file. I am not using gnuplot for a long time, but i think a space delimited file can be used. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Asking Favor For the Script of Median Filter
On Mar 27, 2011, at 10:56 AM, chuan_zl wrote: Hello,everybody. My name is Chuan Zun Liang. I come from Malaysia. I am just a beginner for R. Kindly to ask favor about median filter. The problem I facing as below: x-matrix(sample(1:30,25),5,5) x [,1] [,2] [,3] [,4] [,5] [1,]78 30 29 13 [2,]46 1259 [3,] 253 22 14 24 [4,]2 15 26 23 19 [5,] 28 18 10 11 20 This is example original matrices of an image. I want apply with median filter with window size 3X# to remove salt and pepper noise in my matric. Here are the script I attend to writing.The script and output shown as below: MedFilter-function(mat,sz) + {out-matrix(0,nrow(mat),ncol(mat)) + for(p in 1:(nrow(mat)-(sz-1))) + {for(q in 1:(ncol(mat)-(sz-1))) + {outrow-median(as.vector(mat[p:(p+(sz-1)),q:(q+(sz-1))])) + out[(p+p+(sz-1))/2,(q+q+(sz-1))/2]-outrow}} + out} Noting that median is probably the rate-limiting factor, I looked for another way to get the middle of 9 items. Using order seem faster: system.time( replicate(10, x2s - sort(x2))) user system elapsed 9.829 0.212 10.029 system.time( replicate(10, x2m - median(x2))) user system elapsed 7.169 0.126 7.272 system.time( replicate(10, x2s -x2[order(x2)[5] ])) user system elapsed 1.907 0.051 1.960 So see if this is any faster. On my system it's about three times faster: x - matrix(sample(364*364), 364,364) out - matrix(0, 364,364) for(xi in 1:(nrow(x)-2)) { for(yi in 1:(ncol(x)-2) ) { xm - x[xi+0:2, yi+0:2] d[xi+1, yi+1] -xm[order(xm)[5] ]}} #-tests -- system.time(for(xi in 1:(nrow(x)-2)) { + for(yi in 1:(ncol(x)-2) ) { + xm - x[xi+0:2, yi+0:2] + d[xi+1, yi+1] -xm[order(xm)[5] ]}} ) user system elapsed 3.806 0.083 3.887 system.time(MedFilter(x,3) ) user system elapsed 11.242 0.202 11.427 MedFilter(x,3) [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]08 12 140 [3,]0 12 14 190 [4,]0 18 15 200 [5,]00000 Example to getting value 8 and 12 as below: 7 8 30 8 30 29 4 6 12 (median=8) 6 12 5 (median=12) 25 3 22 3 22 14 Even the script can give output. However, it is too slow. My image size is 364*364. It is time consumption. Is it get other ways to improving it? David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overlaying
Dear List, I am working with a small (3 columns and 9 rows) data table, which contains 9 observations, their mean values and standard deviations (I extracted these data from a huge set and I cannot use the original data). I plotted means (y-axis) and the observations (x-axis) using the plot() command. However, I am not sure how to plot the standard deviation data on top of this. This kind of chart will save me time and space so I want to overlay standard deviation values. I appreciate your suggestions in terms of how to do this or using a different type of graph. Thank you, -- BÜLENT ARIKAN, PhD Postdoctoral Scholar Center for Social Dynamics and Complexity School of Human Evolution and Social Change Arizona State University Tempe - AZ 85287-2402 [[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] Structural equation modeling in R(lavaan,sem)
I am a new user of the function sem in package sem and lavaan for structural equation modeling 1. I don’t know what is the difference between this function and CFA function, I know that cfa for confirmatory analysis but I don’t know what is the difference between confirmatory analysis and structural equation modeling in the package lavaan. 2. I have data that I want to analyse but I have some missing data I must to impute these missing data and I use this package or there is a method that can handle missing data (I want to avoid to delete observations where I have some missing data) 3. I have to use variables that arn’t normally distributed , even if I tried to do some transformation to theses variables t I cant success to have normally distributed data , so I decide to work with these data non normally distributed, my question my result will be ok even if I have non normally distributd data. 4. If I work with the package ggm for separation d , without latent variables we will have the same result as SEM function I guess 5. How about when we have the number of observation is small n, and what is the method to know that we have the minimum of observation required?? Thanks a lot -- View this message in context: http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3409642.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] MARS response weights
I am trying to use the mars function from mda package and cannot figure out how to specify the response weights wp parameter. I have tried a vector of size = num_observations as well as num_levels of my response, but in both cases, the function fails with some error about invalid array length. ThanksVijay [[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] ggplot2: ndensity and density parameters
Hello, if I want to compare the distributions of two datasets using ggplots, how should I choose the density type? More exactly, what assumptions and are behind the ndensity and density parameters? And when should they be used? See http://had.co.nz/ggplot2/stat_bin.html While I understand that one is scaled and the other one is not, I do not understand which one I should rely on. The distributions look very different when I try both alternatives. 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] Importing many files from a single code
Exactly what do you mean by import? What commands are you using? You can get a list of the files in a directory and then iterate through reading each one in. If you use 'lapply', you can 'read.table' in some data frames and then 'rbind' them into a single data frame. You need to be more specific on the problem you are trying to solve. Hey, I am new to using R and I have a similar problem.. I have 50data sets saved and need to write a function to combine 2 data sets out of the 50. combine.data-function(data1,data2){ for(data1 in (0:50)) for(data2 in (0:50)) rbind(read.table(tree.data1.dat),read.table(tree.data2.dat)) } Could you please help me.. :) Thanks heaps! -- View this message in context: http://r.789695.n4.nabble.com/Importing-many-files-from-a-single-code-tp838084p3409688.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.
Re: [R] overlaying
Tena koe There are many ways. I tend to use the arrows() function. See ?arrows HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Bulent Arikan Sent: Monday, 28 March 2011 10:45 a.m. To: r-help@r-project.org Subject: [R] overlaying Dear List, I am working with a small (3 columns and 9 rows) data table, which contains 9 observations, their mean values and standard deviations (I extracted these data from a huge set and I cannot use the original data). I plotted means (y-axis) and the observations (x-axis) using the plot() command. However, I am not sure how to plot the standard deviation data on top of this. This kind of chart will save me time and space so I want to overlay standard deviation values. I appreciate your suggestions in terms of how to do this or using a different type of graph. Thank you, -- BÜLENT ARIKAN, PhD Postdoctoral Scholar Center for Social Dynamics and Complexity School of Human Evolution and Social Change Arizona State University Tempe - AZ 85287-2402 [[alternative HTML version deleted]] The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overlaying
--- On Sun, 3/27/11, Bulent Arikan bulent.ari...@gmail.com wrote: From: Bulent Arikan bulent.ari...@gmail.com Subject: [R] overlaying To: r-help@r-project.org Received: Sunday, March 27, 2011, 5:45 PM Dear List, I am working with a small (3 columns and 9 rows) data table, which contains 9 observations, their mean values and standard deviations (I extracted these data from a huge set and I cannot use the original data). I plotted means (y-axis) and the observations (x-axis) using the plot() command. However, I am not sure how to plot the standard deviation data on top of this. This kind of chart will save me time and space so I want to overlay standard deviation values. I appreciate your suggestions in terms of how to do this or using a different type of graph. Thank you, -- BÜLENT ARIKAN, PhD Postdoctoral Scholar Center for Social Dynamics and Complexity School of Human Evolution and Social Change Arizona State University Tempe - AZ 85287-2402 # Usesarrows to produce confidence intervals for a set of values. low - c(312.9460, 312.9419, 312.9422, 312.9380 ) mass - c(312.9476, 312.9435, 312.9438 , 312.9396 ) high - c(312.9492, 312.9451, 312.9454, 312.9412) yaxis - seq(1,4,by=1) plot(x = mass, y = yaxis, pch=17, xlim = c(312.9378,312.9500), axes=FALSE, xlab = 'mass', ylab = '', main = 'Mass/Intensity Problem') labs - seq(312.8, 312.95, by = 0.0005) axis(1, at = labs, labels = labs) axis(2, at = yaxis, las = 2) arrows(x0 = low, x1 = high, y0 = yaxis, y1 = yaxis, length=0.1, code = 3, col = 4, angle = 90) box() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Asking Favor For the Script of Median Filter
On Mar 27, 2011, at 1:07 PM, Mike Marchywka wrote: You obviously want to delegate inner loops to R packages that execute as native, hopefully optimized, code. Generally a google search that starts with R CRAN will help. In this case it looks like a few packages available, http://www.google.com/search?sclient=psyhl=enq=R+cran+median+filter Did you find any that include a 2D median filter? All the ones I looked at were for univariate data. -- David. Date: Sun, 27 Mar 2011 07:56:11 -0700 From: chuan...@hotmail.com To: r-help@r-project.org Subject: [R] Asking Favor For the Script of Median Filter Hello,everybody. My name is Chuan Zun Liang. I come from Malaysia. I am just a beginner for R. Kindly to ask favor about median filter. The problem I facing as below: x-matrix(sample(1:30,25),5,5) x [,1] [,2] [,3] [,4] [,5] [1,] 7 8 30 29 13 [2,] 4 6 12 5 9 [3,] 25 3 22 14 24 [4,] 2 15 26 23 19 [5,] 28 18 10 11 20 This is example original matrices of an image. I want apply with median filter with window size 3X# to remove salt and pepper noise in my matric. Here are the script I attend to writing.The script and output shown as below: MedFilter-function(mat,sz) + {out-matrix(0,nrow(mat),ncol(mat)) + for(p in 1:(nrow(mat)-(sz-1))) + {for(q in 1:(ncol(mat)-(sz-1))) + {outrow-median(as.vector(mat[p:(p+(sz-1)),q:(q+(sz-1))])) + out[(p+p+(sz-1))/2,(q+q+(sz-1))/2]-outrow}} + out} MedFilter(x,3) [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 8 12 14 0 [3,] 0 12 14 19 0 [4,] 0 18 15 20 0 [5,] 0 0 0 0 0 Example to getting value 8 and 12 as below: 7 8 30 8 30 29 4 6 12 (median=8) 6 12 5 (median=12) 25 3 22 3 22 14 Even the script can give output. However, it is too slow. My image size is 364*364. It is time consumption. Is it get other ways to improving it? Best Wishes Chuan -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Structural equation modeling in R(lavaan,sem)
On 27 March 2011 12:12, jouba antr...@hotmail.com wrote: I am a new user of the function sem in package sem and lavaan for structural equation modeling 1. I dont know what is the difference between this function and CFA function, I know that cfa for confirmatory analysis but I dont know what is the difference between confirmatory analysis and structural equation modeling in the package lavaan. Confirmatory factor analyses are a class of SEMs. All CFAs are SEMs, some SEMs are CFA. Usually (but definitions vary), if you have a measurement model only, that's a CFA. If you have a structural model too, that's SEM. If you don't understand this distinction, might I suggest a little more reading before you launch into the world of lavaan? Things can get quite tricky quite quickly. 2. I have data that I want to analyse but I have some missing data I must to impute these missing data and I use this package or there is a method that can handle missing data (I want to avoid to delete observations where I have some missing data) No, you can use full information maximum likelihood estimation (= direct ML) to model data in the presence of missing data. 3. I have to use variables that arnt normally distributed , even if I tried to do some transformation to theses variables t I cant success to have normally distributed data , so I decide to work with these data non normally distributed, my question my result will be ok even if I have non normally distributd data. Depends. Lavaan can do things like Satorra-Bentler scaled chi-square, which are robust to non-normality, and corrects your chi-square for (multivariate) kurtosis. 4. If I work with the package ggm for separation d , without latent variables we will have the same result as SEM function I guess Not familiar with ggm. I'll leave that for someone else. 5. How about when we have the number of observation is small n, and what is the method to know that we have the minimum of observation required?? Another very difficult question. Short answer: it depends. Sometimes you see recommendations based on the number of participants per parameter, which is usually around 5-10. These are somewhat flawed, but it's better than nothing. Again, I should reiterate that you have a hard road in front of you, and it will be made much easier if you read a couple of introductory SEM texts, which will answer this sort of question. Jeremy -- Jeremy Miles Psychology Research Methods Wiki: www.researchmethodsinpsychology.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Asking Favor For the Script of Median Filter
?runmed -- Bert On Sun, Mar 27, 2011 at 2:44 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 27, 2011, at 10:56 AM, chuan_zl wrote: Hello,everybody. My name is Chuan Zun Liang. I come from Malaysia. I am just a beginner for R. Kindly to ask favor about median filter. The problem I facing as below: x-matrix(sample(1:30,25),5,5) x [,1] [,2] [,3] [,4] [,5] [1,] 7 8 30 29 13 [2,] 4 6 12 5 9 [3,] 25 3 22 14 24 [4,] 2 15 26 23 19 [5,] 28 18 10 11 20 This is example original matrices of an image. I want apply with median filter with window size 3X# to remove salt and pepper noise in my matric. Here are the script I attend to writing.The script and output shown as below: MedFilter-function(mat,sz) + {out-matrix(0,nrow(mat),ncol(mat)) + for(p in 1:(nrow(mat)-(sz-1))) + {for(q in 1:(ncol(mat)-(sz-1))) + {outrow-median(as.vector(mat[p:(p+(sz-1)),q:(q+(sz-1))])) + out[(p+p+(sz-1))/2,(q+q+(sz-1))/2]-outrow}} + out} Noting that median is probably the rate-limiting factor, I looked for another way to get the middle of 9 items. Using order seem faster: system.time( replicate(10, x2s - sort(x2))) user system elapsed 9.829 0.212 10.029 system.time( replicate(10, x2m - median(x2))) user system elapsed 7.169 0.126 7.272 system.time( replicate(10, x2s -x2[order(x2)[5] ])) user system elapsed 1.907 0.051 1.960 So see if this is any faster. On my system it's about three times faster: x - matrix(sample(364*364), 364,364) out - matrix(0, 364,364) for(xi in 1:(nrow(x)-2)) { for(yi in 1:(ncol(x)-2) ) { xm - x[xi+0:2, yi+0:2] d[xi+1, yi+1] -xm[order(xm)[5] ]}} #-tests -- system.time(for(xi in 1:(nrow(x)-2)) { + for(yi in 1:(ncol(x)-2) ) { + xm - x[xi+0:2, yi+0:2] + d[xi+1, yi+1] -xm[order(xm)[5] ]}} ) user system elapsed 3.806 0.083 3.887 system.time(MedFilter(x,3) ) user system elapsed 11.242 0.202 11.427 MedFilter(x,3) [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 8 12 14 0 [3,] 0 12 14 19 0 [4,] 0 18 15 20 0 [5,] 0 0 0 0 0 Example to getting value 8 and 12 as below: 7 8 30 8 30 29 4 6 12 (median=8) 6 12 5 (median=12) 25 3 22 3 22 14 Even the script can give output. However, it is too slow. My image size is 364*364. It is time consumption. Is it get other ways to improving it? David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Asking Favor For the Script of Median Filter
Oops. My error! You wanted a 2D filter. I suspect a search will find some implementation, but you may wish to consider ?loess instead (there are numerous others, no doubt). -- Bert On Sun, Mar 27, 2011 at 3:30 PM, David Winsemius dwinsem...@comcast.net wrote: On Mar 27, 2011, at 1:07 PM, Mike Marchywka wrote: You obviously want to delegate inner loops to R packages that execute as native, hopefully optimized, code. Generally a google search that starts with R CRAN will help. In this case it looks like a few packages available, http://www.google.com/search?sclient=psyhl=enq=R+cran+median+filter Did you find any that include a 2D median filter? All the ones I looked at were for univariate data. -- David. Date: Sun, 27 Mar 2011 07:56:11 -0700 From: chuan...@hotmail.com To: r-help@r-project.org Subject: [R] Asking Favor For the Script of Median Filter Hello,everybody. My name is Chuan Zun Liang. I come from Malaysia. I am just a beginner for R. Kindly to ask favor about median filter. The problem I facing as below: x-matrix(sample(1:30,25),5,5) x [,1] [,2] [,3] [,4] [,5] [1,] 7 8 30 29 13 [2,] 4 6 12 5 9 [3,] 25 3 22 14 24 [4,] 2 15 26 23 19 [5,] 28 18 10 11 20 This is example original matrices of an image. I want apply with median filter with window size 3X# to remove salt and pepper noise in my matric. Here are the script I attend to writing.The script and output shown as below: MedFilter-function(mat,sz) + {out-matrix(0,nrow(mat),ncol(mat)) + for(p in 1:(nrow(mat)-(sz-1))) + {for(q in 1:(ncol(mat)-(sz-1))) + {outrow-median(as.vector(mat[p:(p+(sz-1)),q:(q+(sz-1))])) + out[(p+p+(sz-1))/2,(q+q+(sz-1))/2]-outrow}} + out} MedFilter(x,3) [,1] [,2] [,3] [,4] [,5] [1,] 0 0 0 0 0 [2,] 0 8 12 14 0 [3,] 0 12 14 19 0 [4,] 0 18 15 20 0 [5,] 0 0 0 0 0 Example to getting value 8 and 12 as below: 7 8 30 8 30 29 4 6 12 (median=8) 6 12 5 (median=12) 25 3 22 3 22 14 Even the script can give output. However, it is too slow. My image size is 364*364. It is time consumption. Is it get other ways to improving it? Best Wishes Chuan -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Asking Favor For the Script of Median Filter
CC: chuan...@hotmail.com; r-help@r-project.org From: dwinsem...@comcast.net To: marchy...@hotmail.com Subject: Re: [R] Asking Favor For the Script of Median Filter Date: Sun, 27 Mar 2011 18:30:48 -0400 On Mar 27, 2011, at 1:07 PM, Mike Marchywka wrote: You obviously want to delegate inner loops to R packages that execute as native, hopefully optimized, code. Generally a google search that starts with R CRAN will help. In this case it looks like a few packages available, http://www.google.com/search?sclient=psyhl=enq=R+cran+median+filter Did you find any that include a 2D median filter? All the ones I looked at were for univariate data. I put almost zero thought or effort into that but an interested party could modify the words a bit and and, for example image and one of the first interesting hits is this, http://cran.r-project.org/web/packages/biOps/biOps.pdf x - readJpeg(system.file(samples, violet.jpg, package=biOps)) y - imgBlockMedianFilter(x, 5) -- David. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] portfolioBacktest in fPortfolio
Hello. I am trying to use the portfolio backtesting function in fPortfolio package, but I don't now why in my version of fPortfolio I don't have either the portfolioBactest nor the portfolioBacktesting functions. Does anybody knows what might be going on? thank you Felipe Parra [[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] portfolioBacktest in fPortfolio
LFP == Luis Felipe Parra felipe.pa...@quantil.com.co on Mon, 28 Mar 2011 09:10:33 +0800 LFP Hello. I am trying to use the portfolio backtesting function LFP in fPortfolio LFP package, but I don't now why in my version of fPortfolio I LFP don't have either LFP the portfolioBactest nor the portfolioBacktesting LFP functions. Does anybody LFP knows what might be going on? LFP LFP thank you LFP LFP Felipe Parra Hi Luis, You can find fPortfolioBacktest on R-forge (https://r-forge.r-project.org/projects/rmetrics/). HTH, Yohan -- PhD candidate Swiss Federal Institute of Technology Zurich www.ethz.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Structural equation modeling in R(lavaan,sem)
Jeremy thanks a lot for your response I have read sem package help and I currently reading the help of lavaan I see that there is also an other function called lavaan can do the SEM analysis So I wonder what is the difference between this function and the sem function Also I am wondering in the case where we have categorical variables and discreet variables?? For me one of the problems is how we will calculate the correlation matrix , mainly when we have to calculate these between a quantitative and qualitative variables, I wonder if polycor package is the best solution for this or there is other ideas for functions witch can do the work Cordially Antra EL MOUSSELLY Date: Sun, 27 Mar 2011 18:08:02 -0700 From: ml-node+3410447-849581659-225...@n4.nabble.com To: antr...@hotmail.com Subject: Re: Structural equation modeling in R(lavaan,sem) On 27 March 2011 12:12, jouba [hidden email] wrote: I am a new user of the function sem in package sem and lavaan for structural equation modeling 1. I donât know what is the difference between this function and CFA function, I know that cfa for confirmatory analysis but I donât know what is the difference between confirmatory analysis and structural equation modeling in the package lavaan. Confirmatory factor analyses are a class of SEMs. All CFAs are SEMs, some SEMs are CFA. Usually (but definitions vary), if you have a measurement model only, that's a CFA. If you have a structural model too, that's SEM. If you don't understand this distinction, might I suggest a little more reading before you launch into the world of lavaan? Things can get quite tricky quite quickly. 2. I have data that I want to analyse but I have some missing data I must to impute these missing data and I use this package or there is a method that can handle missing data (I want to avoid to delete observations where I have some missing data) No, you can use full information maximum likelihood estimation (= direct ML) to model data in the presence of missing data. 3. I have to use variables that arnât normally distributed , even if I tried to do some transformation to theses variables t I cant success to have normally distributed data , so I decide to work with these data non normally distributed, my question my result will be ok even if I have non normally distributd data. Depends. Lavaan can do things like Satorra-Bentler scaled chi-square, which are robust to non-normality, and corrects your chi-square for (multivariate) kurtosis. 4. If I work with the package ggm for separation d , without latent variables we will have the same result as SEM function I guess Not familiar with ggm. I'll leave that for someone else. 5. How about when we have the number of observation is small n, and what is the method to know that we have the minimum of observation required?? Another very difficult question. Short answer: it depends. Sometimes you see recommendations based on the number of participants per parameter, which is usually around 5-10. These are somewhat flawed, but it's better than nothing. Again, I should reiterate that you have a hard road in front of you, and it will be made much easier if you read a couple of introductory SEM texts, which will answer this sort of question. Jeremy -- Jeremy Miles Psychology Research Methods Wiki: www.researchmethodsinpsychology.com [[alternative HTML version deleted]] __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below:http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3410447.html To unsubscribe from Structural equation modeling in R(lavaan,sem), click here. -- View this message in context: http://r.789695.n4.nabble.com/Structural-equation-modeling-in-R-lavaan-sem-tp3409642p3410587.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Import variable labels to data frame columns
Hi, I'm new to R and I'm stuck trying to import some data from a .dat file I've been given. The tricky bit for me is that the data has both variable values and labels? The data looks like this, Id=1 time=2011-03-27 19:23:40 start=1.4018 end=1.4017 Id=2 time=2011-03-27 19:23:40 start=1.8046 end=1.8047 Id=1 time=2011-03-27 19:23:50 start=1.4017 end=1.4018 Id=2 time=2011-03-27 19:23:50 start=1.8047 end=1.8046 Is there a way to read the file into a dataframe or martix, so each line of the file is read into a row, and the data labels are the columns. I'm try to get it to look like this? Id time start end 1 2011-03-27 19:23:40 1.4018 1.4017 2 2011-03-27 19:23:40 1.8046 1.8047 1 2011-03-27 19:23:50 1.4017 1.4018 2 2011-03-27 19:23:50 1.8047 1.8046 Its driving me nuts . Any help appreciated -- View this message in context: http://r.789695.n4.nabble.com/Import-variable-labels-to-data-frame-columns-tp3410525p3410525.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] Splitting Datasets
On R 2.12 for Mac OSX, I have a dataset with both numerical and character values. I want to split dataset ZIDL, into individual datasets based on the string content of variable Dept. I can create one subset dataset at a time using a script I found on the net, but rather than run the same function 17 times, can R look at the Dept variable and create subset datasheets of the main datasheet (one for each department) with a single command? In Minitab, this would be the Split Worksheet function. I am horrible at scripting, but trying to learn fast. Thanks in advance, Robert [[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] Importing many files from a single code
Dear Ram Kumar Basent: I suggest you restore you file is list. I give my example that I read 50 image by 50 folder. imgA-list() -create an empty list for(i in 1:50) -how many file you need to looping. { imgA[[i]]-read.jpeg(paste(c:/DataCentre/DataPisA/A,i,FP3.jpg,sep=))) } This is my example how I read 50 image in 50 folders. Hope this will hepl you. Best Wishes Chuan -- View this message in context: http://r.789695.n4.nabble.com/Importing-many-files-from-a-single-code-tp838084p3409909.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.
Re: [R] Splitting Datasets
Wainscott, Robert LT robert.wainscott at cvn74.navy.mil writes: I want to split dataset ZIDL, into individual datasets based on the string content of variable Dept. There are many, many ways to do this, depending on what you're really after. Here's one: depts = levels(factor(zidl$dept)) for (i in 1:length(depts)) { tiny.dataset = subset(zidl, dept==depts[i]) # now do whatever processing you need with tiny.dataset } Read the Introduction to R and the help page for the subset command, i.e., ?subset __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] altering a call variable from quote()
I have a variable of mode call: b = quote(b==3) b b == 3 Now I want to append x 2 to the value of b. How do I do that? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Degrees of freedom for lm in logLik and AIC
I have a question about the computation of the degrees of freedom in a linear model: x - runif(20); y - runif(20) f - lm(y ~ x) logLik(f) 'log Lik.' -1.968056 (df=3) The 3 is coming from f$rank + 1. Shouldn't it be f$rank? This affects AIC(f). Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Degrees-of-freedom-for-lm-in-logLik-and-AIC-tp3410687p3410687.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.
Re: [R] Splitting Datasets
Please start by read ing An Introduction to R. You need to understand R data structures and how it works AS A LANGUAGE. Forget about Minitab (while you are in R). ?tapply -- Bert On Sun, Mar 27, 2011 at 5:50 PM, Wainscott, Robert LT robert.wainsc...@cvn74.navy.mil wrote: On R 2.12 for Mac OSX, I have a dataset with both numerical and character values. I want to split dataset ZIDL, into individual datasets based on the string content of variable Dept. I can create one subset dataset at a time using a script I found on the net, but rather than run the same function 17 times, can R look at the Dept variable and create subset datasheets of the main datasheet (one for each department) with a single command? In Minitab, this would be the Split Worksheet function. I am horrible at scripting, but trying to learn fast. Thanks in advance, Robert [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Import variable labels to data frame columns
AjayT ajaytalati at googlemail.com writes: The data looks like this, Id=1 time=2011-03-27 19:23:40 start=1.4018 end=1.4017 Id=2 time=2011-03-27 19:23:40 start=1.8046 end=1.8047 Something like this would do: lines = scan(file, nlines=1, ...) fields = strsplit(lines[1], \s+, perl=TRUE) k.v.pairs = sapply(fields, function(f) { strsplit(f, =) }) df.row = sapply(k.v.pairs, function(k.v) { k.v[2] }) You can then rbind() the df.row values to get a data.frame. Note that this assumes that all your input records have all the same fields and all in the same order. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Splitting Datasets
Hi, Answers inline: On Sun, Mar 27, 2011 at 8:50 PM, Wainscott, Robert LT robert.wainsc...@cvn74.navy.mil wrote: On R 2.12 for Mac OSX, I have a dataset with both numerical and character values. I want to split dataset ZIDL, into individual datasets based on the string content of variable Dept. I can create one subset dataset at a time using a script I found on the net, but rather than run the same function 17 times, can R look at the Dept variable and create subset datasheets of the main datasheet (one for each department) with a single command? In Minitab, this would be the Split Worksheet function. There is a split function in R: R ?split I am horrible at scripting, but trying to learn fast. As Bert mentioned, you have to learn the basics of the language first, otherwise you'll never get past the stabbing in the dark feeling. You can start here: http://cran.r-project.org/doc/manuals/R-intro.html Take a couple of hours to go through that -- there's no way to learn fast without first starting slow. Good luck, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] altering a call variable from quote()
Jack Tanner ihok at hotmail.com writes: b = quote(b==3) Now I want to append x 2 to the value of b. How do I do that? Never mind, I figured it out: substitute(b x 2, list(b=b)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] maximum likelihood accuracy - comparison with Stata
Hi everyone, I am looking to do some manual maximum likelihood estimation in R. I have done a lot of work in Stata and so I have been using output comparisons to get a handle on what is happening. I estimated a simple linear model in R with lm() and also my own maximum likelihood program. I then compared the output with Stata. Two things jumped out at me. Firstly, in Stata my coefficient estimates are identical in both the OLS estimation by -reg- and the maximum likelihood estimation using Stata's ml lf command. In R my coefficient estimates differ slightly between lm() and my own maximum likelihood estimation. Secondly, the estimates for sigma2 are very different between R and Stata. 3.14 in R compared to 1.78 in Stata. I have copied my maximum likelihood program below. It is copied from a great intro to MLE in R by Macro Steenbergen http://artsci.wustl.edu/~jmonogan/computing/r/MLE_in_R.pdf Any comments are welcome. In particular I would like to know why the estimate of sigma2 is so different. I would also like to know about the accuracy of the coefficient estimates. ## ols ols - lm(Kmenta$consump ~ Kmenta$price + Kmenta$income) coef(summary(ols)) ## mle y - matrix(Kmenta$consump) x - cbind(1, Kmenta$price, Kmenta$income) ols.lf - function(theta, y, x) { N - nrow(y) K - ncol(x) beta - theta[1:K] sigma2 - theta[K+1] e - y - x%*%beta logl - -0.5*N*log(2*pi)-0.5*N*log(sigma2)-((t(e)%*%e)/(2*sigma2)) return(-logl) } p - optim(c(0,0,0,2), ols.lf, method=BFGS, hessian=T, y=y, x=x) OI - solve(p$hessian) se - sqrt(diag(OI)) se - se[1:3] beta - p$par[1:3] results - cbind(beta, se) results sigma2 - p$par[4] sigma2 Kind regards, Alex Olssen Motu Research Wellington New Zealand __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Import variable labels to data frame columns
On Sun, Mar 27, 2011 at 9:40 PM, AjayT ajaytal...@googlemail.com wrote: Hi, I'm new to R and I'm stuck trying to import some data from a .dat file I've been given. The tricky bit for me is that the data has both variable values and labels? The data looks like this, Id=1 time=2011-03-27 19:23:40 start=1.4018 end=1.4017 Id=2 time=2011-03-27 19:23:40 start=1.8046 end=1.8047 Id=1 time=2011-03-27 19:23:50 start=1.4017 end=1.4018 Id=2 time=2011-03-27 19:23:50 start=1.8047 end=1.8046 Is there a way to read the file into a dataframe or martix, so each line of the file is read into a row, and the data labels are the columns. I'm try to get it to look like this? Id time start end 1 2011-03-27 19:23:40 1.4018 1.4017 2 2011-03-27 19:23:40 1.8046 1.8047 1 2011-03-27 19:23:50 1.4017 1.4018 2 2011-03-27 19:23:50 1.8047 1.8046 Its driving me nuts . Any help appreciated Here are a few ways. (You may need to adjust widths in the first two solutions.) 1. read.fwf can read read fixed width data: widths - c(3, 2, 5, 20, 6, 13, 4, 6) read.fwf(myfile.dat, widths = widths, col.names = c(NA, Id, NA, time, NA, start, NA, end), colClasses = c(NULL, character, NULL, character, NULL, numeric, NULL, numeric)) 2. or a variation which automatically sets the names widths - c(2, 1, 2, 4, 1, 20, 5, 1, 13, 3, 1, 6) DF - read.fwf(myfile.dat, widths = widths, as.is = TRUE) ix - seq(3, 12, 3) setNames(DF[ix], DF[1, ix-2]) 3. or read it, change the delimiters and read it again with new delimiters. This automatically sets names too and does not need to know the widths. L - readLines(myfile.dat) L - gsub( *(\\w*)=, ,\\1,, L) DF - read.table(textConnection(L), sep = ,, as.is = TRUE) ix - seq(3, 9, 2) setNames(DF[ix], DF[1, ix-1]) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.