Re: [R] plot region too large
On Fri, 15 Sep 2006, Kiermeier, Andreas (PIRSA - SARDI) wrote: The figure margins come from what is set in par(mar), eg layout(matrix(c(1:10),5,2),heights=c(1,rep(2,4))) par(mar) [1] 5.1 4.1 4.1 2.1 There is not enough space left to plot anything with those margins. You will need to make them smaller first, e.g. par(mar=c(1,1,1,1,)) plot(1,1) In which case things work. Or as the underlying cause is that the text is too large for a 5x2 layout, reduce the pointsize or increase the device region of the device in use. Using par(mfrow/mfcol) reduces the text size for large layouts: layout() does not. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kamila Naxerova Sent: Friday, 15 September 2006 13:26 To: r-help@stat.math.ethz.ch Subject: [R] plot region too large Hi! I don't understand this: layout(matrix(c(1:10),5,2),heights=c(1,rep(2,4))) plot(1,1) error in plot.new() : plot region too large Why?? -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] ccf versus acf
I am trying to run a cross-correlation using the ccf() function. When I select plot = TRUE in the ccf() I get a graph which has ACF on the y-axis, which would suggest that these y-values are the auto-correlation values. How should I adjust the code to produce a plot that provides the cross-correlation values? Here is my code: w002dat - read.csv(w054_1128958_08NM174.csv, header=TRUE) w002dat$date - as.Date(w002dat$date,%m/%d/%Y) attach(w002dat) w002ccfhdgw - ccf((gwneg), (hydro), lag.max = 400, type = c(correlation), plot = TRUE, na.action = na.exclude) Thank you Arelia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Kernel Smoothing with more than 2 predictors
Hi, I'm wondering if anyone is aware of any R packages that do kernel smoothing with at least 4 predictors. The dataset I'm working with now has 4 predictors, and I can fit a loess smooth, but loess has the disadvantage that it can produce fitted values outside the range of the response-something a kernel smoother can't do. All the packages I've found so far work for 2 or fewer predictors. If anyone's aware of an R package for kernel smoothing that will work with at least 4 predictors, please let me know. Thanks, Paul Louisell [EMAIL PROTECTED] ARPC [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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
Hello, I am a new user of R statistical project. So, I have a matrix (4 columns and 330 rows) and I would like to have PCA (Principal Component Analysis). Besides, I would like to draw every 30 rows from 330 with a different colour but I dont know how. Could you help me by showing how can I draw every 30 rows with a different colour? Thank you very much Selim - Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos expériences. Cliquez ici. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] execution of source() command
Hi Linux SuSE 10 platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) I have two questions concerning the source(test.R) command. 1) Is there any command which I can put into the test.R script file which aborts the execution of the script? At the moment I use CodeToBeExecutedInScript if (FALSE) { CodeNotToBeExecutedInScript } which is not elegant, but it works. I would prefer something like: CodeToBeExecutedInScript CommandToAbotrExecutionOfScriptFile CodeNotToBeExecutedInScript 2) When I call source(test.R) and it is running for some time. Does changing the file test.R while it is executed change the execution, i.e. does the call of source() load the script file into memory and parses and executes it from there or does it parse and execute the file on the disk? Thanks in advance, Rainer -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help
Do you mean something like this? mat - cbind(rnorm(330),rnorm(330),rnorm(330),rnorm(330)) head(mat) [,1][,2][,3] [,4] [1,] -0.4668818 0.03015618 -0.72568113 0.6053179 [2,] -0.2625691 -2.20022333 -0.93728544 0.5455864 [3,] -3.4599164 0.71049089 -0.91545599 -1.6744806 [4,] -1.2757082 -1.27079001 0.95844728 -0.1208091 [5,] 0.7761458 -0.38686485 -1.51233490 -2.0337612 [6,] 0.5032718 0.40763612 0.08763122 0.9083149 sel - seq(1,330,by=30) matplot(t(mat[sel,]),type=b,pch=15) For principal components analysis, ?princomp or ?prcomp On 14/09/06, Ben Salah Mohamed Selim [EMAIL PROTECTED] wrote: Hello, I am a new user of R statistical project. So, I have a matrix (4 columns and 330 rows) and I would like to have PCA (Principal Component Analysis). Besides, I would like to draw every 30 rows from 330 with a different colour but I don't know how. Could you help me by showing how can I draw every 30 rows with a different colour? Thank you very much Selim - Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos expériences. Cliquez ici. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] predict with logistic regression
I am learning about using logistic regression with glm. Suppose I have dataset: duration - c(45,15,40,83,90,25,35,65,95,35,75,45,50,75,30,25,20,60,70,30,60,61,65,15,20,45,15,25,15,30,40,15,135,20,40) type - c(0,0,0,1,1,1,rep(0,5),1,1,1,0,0,1,1,1,rep(0,4),1,1,0,1,0,1,0,0,rep(1,4)) sore - factor(rep(c(M, F), c(16, 19))) sore.fr - data.frame(duration, type, sore) str(sore.fr) then with glm I have the result. sorethroat.lg - glm(sore ~ type+duration, family=binomial, data=sore.fr) summary(sorethroat.lg, cor=TRUE) If I have a new dataset then predict it, the result: new.sore - data.frame(duration=c(35,25,41,33,30,55,35,62,93,34), type=c(0,1,0,1,0,1,1,1,0,1)) predict(sorethroat.lg, new.sore, type=response) predict(sorethroat.lg, new.sore, type=response) 123456 0.5176877150 0.2750893421 0.5407418590 0.3003664211 0.4984140283 0.3760831903 789 10 0.3068890332 0.4017370393 0.7242061280 0.3036178483 I know that is probability of predict for new dataset. My question is how can I know each probability according to class (sore). I mean that I need the result of predit something like (M=1, F=0): 1 2 3 4 5 6 7 8 9 10 1 0 0 0 1 0 1 1 0 1 Sincerelly, JS __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] ccf versus acf
On Thu, 14 Sep 2006, Werner,Arelia [PYR] wrote: I am trying to run a cross-correlation using the ccf() function. When I select plot = TRUE in the ccf() I get a graph which has ACF on the y-axis, which would suggest that these y-values are the auto-correlation values. But cross-correlations are part of the ACF for a bivariate time series, so why do you think that is a problem? Your example is not reproducible. However, there is a reproducible example on the help page that looks like cross-correlations (look at the value at lag 0). And ccf(mdeaths, fdeaths, ylab=ccf) might be what you are looking for. How should I adjust the code to produce a plot that provides the cross-correlation values? Here is my code: w002dat - read.csv(w054_1128958_08NM174.csv, header=TRUE) w002dat$date - as.Date(w002dat$date,%m/%d/%Y) attach(w002dat) w002ccfhdgw - ccf((gwneg), (hydro), lag.max = 400, type = c(correlation), plot = TRUE, na.action = na.exclude) Thank you Arelia [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. PLEASE do! -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] execution of source() command
On Fri, 15 Sep 2006, Rainer M Krug wrote: Hi Linux SuSE 10 platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 3.1 year 2006 month 06 day01 svn rev38247 language R version.string Version 2.3.1 (2006-06-01) I have two questions concerning the source(test.R) command. 1) Is there any command which I can put into the test.R script file which aborts the execution of the script? At the moment I use CodeToBeExecutedInScript if (FALSE) { CodeNotToBeExecutedInScript } which is not elegant, but it works. I would prefer something like: CodeToBeExecutedInScript CommandToAbotrExecutionOfScriptFile CodeNotToBeExecutedInScript ?stop or ?q, depending on what you mean by 'aborts the execution'. 2) When I call source(test.R) and it is running for some time. Does changing the file test.R while it is executed change the execution, i.e. does the call of source() load the script file into memory and parses and executes it from there or does it parse and execute the file on the disk. The help file says: 'source' causes R to accept its input from the named file or URL (the name must be quoted) or connection. Input is read and 'parse'd by from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. library(fortunes); fortune(WTFM) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] execution of source() command
Prof Brian Ripley wrote: On Fri, 15 Sep 2006, Rainer M Krug wrote: Hi I have two questions concerning the source(test.R) command. 1) Is there any command which I can put into the test.R script file which aborts the execution of the script? At the moment I use CodeToBeExecutedInScript if (FALSE) { CodeNotToBeExecutedInScript } which is not elegant, but it works. I would prefer something like: CodeToBeExecutedInScript CommandToAbotrExecutionOfScriptFile CodeNotToBeExecutedInScript ?stop or ?q, depending on what you mean by 'aborts the execution'. Thanks - I would have expected to find it together with the other flowcontrol commands like if, while, ... 2) When I call source(test.R) and it is running for some time. Does changing the file test.R while it is executed change the execution, i.e. does the call of source() load the script file into memory and parses and executes it from there or does it parse and execute the file on the disk. The help file says: 'source' causes R to accept its input from the named file or URL (the name must be quoted) or connection. Input is read and 'parse'd by from that file until the end of the file is reached, then the parsed expressions are evaluated sequentially in the chosen environment. library(fortunes); fortune(WTFM) Again - thanks a lot for the clarification Rainer -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Beta stochastic simulation
On 9/15/2006 6:43 AM, Mark Pinkerton wrote: Hi Duncan, Thanks for having a look at this. Find attached a zip with all the relevant files to run the simulation. I am running this on Windows XP, R version 2.3.1. Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch ' The correct result for the average annual loss, calculated using a battle tested FFT engine, is 1,609,361 The summary stats from my last run are below: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1142 162698000 13250 mean(totals.losses1) [1] 1619891 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 77949.25 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 2352 2341000749700 14170 mean(totals.losses2) [1] 2341237 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 129695.9 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 00:45 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/14/2006 5:26 PM, Mark Pinkerton wrote: Hi Duncan, I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible. The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Beta stochastic simulation
I have just installed 2.4.0 alpha and the problem persists. Here is the output of the run: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1284 1617000685100 21920 mean(totals.losses1) [1] 1617219 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 78863.17 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1422 2417000819200 11820 mean(totals.losses2) [1] 2417471 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 134866.0 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote: Hi Duncan, Thanks for having a look at this. Find attached a zip with all the relevant files to run the simulation. I am running this on Windows XP, R version 2.3.1. Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch ' The correct result for the average annual loss, calculated using a battle tested FFT engine, is 1,609,361 The summary stats from my last run are below: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1142 162698000 13250 mean(totals.losses1) [1] 1619891 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 77949.25 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 2352 2341000749700 14170 mean(totals.losses2) [1] 2341237 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 129695.9 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 00:45 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/14/2006 5:26 PM, Mark Pinkerton wrote: Hi Duncan, I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible. The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Beta stochastic simulation
On 9/15/2006 7:51 AM, Mark Pinkerton wrote: I have just installed 2.4.0 alpha and the problem persists. Here is the output of the run: Thanks. I'll try your script and see if I can track down what's going on. Duncan Murdoch # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1284 1617000685100 21920 mean(totals.losses1) [1] 1617219 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 78863.17 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1422 2417000819200 11820 mean(totals.losses2) [1] 2417471 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 134866.0 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote: Hi Duncan, Thanks for having a look at this. Find attached a zip with all the relevant files to run the simulation. I am running this on Windows XP, R version 2.3.1. Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch ' The correct result for the average annual loss, calculated using a battle tested FFT engine, is 1,609,361 The summary stats from my last run are below: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1142 162698000 13250 mean(totals.losses1) [1] 1619891 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 77949.25 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 2352 2341000749700 14170 mean(totals.losses2) [1] 2341237 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 129695.9 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 00:45 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/14/2006 5:26 PM, Mark Pinkerton wrote: Hi Duncan, I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible. The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. __ R-help@stat.math.ethz.ch mailing list
Re: [R] Beta stochastic simulation
On 9/15/2006 7:51 AM, Mark Pinkerton wrote: I have just installed 2.4.0 alpha and the problem persists. Here is the output of the run: When I run it, I get a series of warning messages from qbeta. Do you get those? Duncan Murdoch # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1284 1617000685100 21920 mean(totals.losses1) [1] 1617219 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 78863.17 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1422 2417000819200 11820 mean(totals.losses2) [1] 2417471 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 134866.0 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote: Hi Duncan, Thanks for having a look at this. Find attached a zip with all the relevant files to run the simulation. I am running this on Windows XP, R version 2.3.1. Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch ' The correct result for the average annual loss, calculated using a battle tested FFT engine, is 1,609,361 The summary stats from my last run are below: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1142 162698000 13250 mean(totals.losses1) [1] 1619891 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 77949.25 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 2352 2341000749700 14170 mean(totals.losses2) [1] 2341237 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 129695.9 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 00:45 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/14/2006 5:26 PM, Mark Pinkerton wrote: Hi Duncan, I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible. The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. __ R-help@stat.math.ethz.ch mailing list
[R] missing data codes
Dear all, I am new to R. I wish to use R's multiple imputation to deal with missing data. I have a data set with the size around 300 observations and 150 variables. I checked the help function in R and could not locate how to write the codes for this. can anyone give a hand? Do appreciate your time and kindness! Q. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Beta stochastic simulation
Yes, indeed I do. Is there any way I can dig into these a bit more? I have also just tried using the OO inverse beta from the distr package and this seems to work. Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote: Hi Duncan, Thanks for having a look at this. Find attached a zip with all the relevant files to run the simulation. I am running this on Windows XP, R version 2.3.1. Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch ' The correct result for the average annual loss, calculated using a battle tested FFT engine, is 1,609,361 The summary stats from my last run are below: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1142 162698000 13250 mean(totals.losses1) [1] 1619891 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 77949.25 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 2352 2341000749700 14170 mean(totals.losses2) [1] 2341237 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 129695.9 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 00:45 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/14/2006 5:26 PM, Mark Pinkerton wrote: Hi Duncan, I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible. The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Beta stochastic simulation
On 9/15/2006 9:06 AM, Mark Pinkerton wrote: Yes, indeed I do. Is there any way I can dig into these a bit more? I have also just tried using the OO inverse beta from the distr package and this seems to work. This is pretty irritating. You were getting warnings from R that the calculations were inaccurate, and you didn't think that was worth mentioning? I'll continue working on this after Risk Management Solutions compensates me for my wasted time, and pays me in advance for additional work. Duncan Murdoch Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 12:15 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/15/2006 6:43 AM, Mark Pinkerton wrote: Hi Duncan, Thanks for having a look at this. Find attached a zip with all the relevant files to run the simulation. I am running this on Windows XP, R version 2.3.1. Does the error still occur in a recent alpha build? It's downloadable from CRAN, in cran.r-project.org/bin/windows/base/rtest.html (though I notice the version there is a week old; I'd better kick the build script). Duncan Murdoch ' The correct result for the average annual loss, calculated using a battle tested FFT engine, is 1,609,361 The summary stats from my last run are below: # Summary stats summary(totals.losses1) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 1142 162698000 13250 mean(totals.losses1) [1] 1619891 sd(totals.losses1)/sqrt(length(totals.losses1)) [1] 77949.25 summary(totals.losses2) Min. 1st Qu.Median Mean 3rd Qu. Max. 0 0 2352 2341000749700 14170 mean(totals.losses2) [1] 2341237 sd(totals.losses2)/sqrt(length(totals.losses2)) [1] 129695.9 Thanks, Mark Mark Pinkerton Risk Management Solutions Peninsular House 30 Monument Street London EC3R 8HB UK www.RMS.com Tel: +44 20 7444 7783 Fax: +44 20 7444 7601 -Original Message- From: Duncan Murdoch [mailto:[EMAIL PROTECTED] Sent: 15 September 2006 00:45 To: Mark Pinkerton Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Beta stochastic simulation On 9/14/2006 5:26 PM, Mark Pinkerton wrote: Hi Duncan, I had also validated the logic with a simple test which is why I was surprised by the differences I was seeing from tthe more complex simulation. I am running R on a Windows 2000 - I'll have to check which version at my desk tomorrow but it's pretty up to date, maybe 6 monthes old. Attached is a code snippet from my simulation program which is used to estimate multi-event annual losses for US hurricanes. The event set being sampled from is quite large (~14000) with each event and account combination having a unique beta loss distribution. Simply swapping lines 23 and 24 has the effect on results that I mentioned in the previous email. The simulation is large enough that the MC error in the estimated means are negligible. The code you sent isn't usable, because it's missing your data. Could you please do the following? - verify that the behaviour still happens in the current alpha test version - try to simplify the example code so someone else can run it? It could be that certain values of alpha and beta trigger a bug but the ones I tried were fine. Duncan Murdoch This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. This message and any attachments contain information that may be RMS Inc. confidential and/or privileged. If you are not the intended recipient (or authorized to receive for the intended recipient), and have received this message in error, any use, disclosure or distribution is strictly prohibited. If you have received this message in error, please notify the sender immediately by replying to the e-mail and permanently deleting the message from your computer and/or storage system. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list
[R] graphics and 'layout' question
Hello, I got stuck with a graphics question: I've 3 figures that I present on a single page (window) via 'layout'. The layout is layout(matrix(c(1,1,2,3), 2, 2, byrow=TRUE)); so that the frst plot spans the both columns in row one. Now I'd like to magnify the fist figure so that it takes 20% more vertical space (i.e. more space for the y-axis). How would I do this in R? thanks a lot for your help, Arne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] missing data codes
You've not given us much information to go on! Have you tried help(aregImpute,package=Hmisc) On 15/09/06, Qiong Wang [EMAIL PROTECTED] wrote: Dear all, I am new to R. I wish to use R's multiple imputation to deal with missing data. I have a data set with the size around 300 observations and 150 variables. I checked the help function in R and could not locate how to write the codes for this. can anyone give a hand? Do appreciate your time and kindness! Q. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] graphics and 'layout' question
[EMAIL PROTECTED] wrote: Hello, I got stuck with a graphics question: I've 3 figures that I present on a single page (window) via 'layout'. The layout is layout(matrix(c(1,1,2,3), 2, 2, byrow=TRUE)); so that the frst plot spans the both columns in row one. Now I'd like to magnify the fist figure so that it takes 20% more vertical space (i.e. more space for the y-axis). How would I do this in R? Are you looking for the heights argument? For example: nf - layout(matrix(c(1,1,2,3), 2, 2, byrow=TRUE), heights=c(70,30)) layout.show(nf) thanks a lot for your help, Arne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] graphics and 'layout' question
Use the heights parameter in the layout function, as shown in ?layout. For example, to get the first figure to be twice as tall as the other two, use: layout(matrix(c(1,1,2,3),2,2,byrow=TRUE),heights=c(2,1)) layout.show(3) On 15/09/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hello, I got stuck with a graphics question: I've 3 figures that I present on a single page (window) via 'layout'. The layout is layout(matrix(c(1,1,2,3), 2, 2, byrow=TRUE)); so that the frst plot spans the both columns in row one. Now I'd like to magnify the fist figure so that it takes 20% more vertical space (i.e. more space for the y-axis). How would I do this in R? thanks a lot for your help, Arne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] missing data codes
See MICE http://www.multiple-imputation.com/ -Original Message- From: David Barron [mailto:[EMAIL PROTECTED] Sent: sexta-feira, 15 de Setembro de 2006 14:38 To: Qiong Wang; r-help Subject: Re: [R] missing data codes You've not given us much information to go on! Have you tried help(aregImpute,package=Hmisc) On 15/09/06, Qiong Wang [EMAIL PROTECTED] wrote: Dear all, I am new to R. I wish to use R's multiple imputation to deal with missing data. I have a data set with the size around 300 observations and 150 variables. I checked the help function in R and could not locate how to write the codes for this. can anyone give a hand? Do appreciate your time and kindness! Q. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] graphics and 'layout' question
[EMAIL PROTECTED] wrote: Hello, I got stuck with a graphics question: I've 3 figures that I present on a single page (window) via 'layout'. The layout is layout(matrix(c(1,1,2,3), 2, 2, byrow=TRUE)); so that the frst plot spans the both columns in row one. Now I'd like to magnify the fist figure so that it takes 20% more vertical space (i.e. more space for the y-axis). How would I do this in R? From ?layout heights: a vector of values for the heights of rows on the device. Relative and absolute heights can be specified, see 'widths' above. So something like layout(matrix(c(1,1,2,3),2,2,byrow = TRUE), heights = c(0.6, 0.4)) should do the trick. Best, Jim thanks a lot for your help, Arne __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- James W. MacDonald, M.S. Biostatistician Affymetrix and cDNA Microarray Core University of Michigan Cancer Center 1500 E. Medical Center Drive 7410 CCGC Ann Arbor MI 48109 734-647-5623 ** Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] group bunch of lines in a data.frame, an additional requirement
(re)-Hello I actually thought about another possibility with a 1 column, a sum (instead of a mean), and a division of the columns for which I want the mean: DF = data.frame( V1=c(A,A,A,B,B,C) , V2=c(1,3,2,0.5,0.9,5.0), V3=c(200,800,200,20,50,70), V4=c(ID1,ID1,ID1,ID2,ID2,ID3)) DF2 = cbind(DF,o=rep(1,length(DF[,1]))) DF3 = aggregate(DF2[,c(2,3,5)], data.frame(code=DF2[,1],id=DF2[,4]), sum, na.rm=T) DF3[,3:4]=DF3[,3:4]/DF3[,5] DF3 code id V2 V3 o 1A ID1 2.0 400 3 2B ID2 0.7 35 2 3C ID3 5.0 70 1 Thanks again, Best, Emmanuel On 9/15/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Dear Mark, dear Gabor, Thanks again for your help! It is great to be able to get answers when no-one (can you believe this?) uses R in your lab. The package doBy looks really convenient for many puposes. Best, Emmanuel On 9/15/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are three different ways to do it: # base R fb - function(x) c(V1 = x$V1[1], V4 = x$V4[1], V2.mean = mean(x$V2), V3.mean = mean(x$V3), n = length(x$V1)) do.call(rbind, by(DF, DF[c(1,4)], fb)) # package doBy library(doBy) summaryBy(V2 + V3 ~ V1 + V4, DF, FUN = c(mean, length))[,-5] # package reshape library(reshape) f - function(x) c(mean = mean(x), n = length(x)) cast(melt(DF, id = c(1,4)), V1 + V4 ~ variable, fun.aggregate = f)[,-6] # base R fb - function(x) +c(V1 = x$V1[1], V4 = x$V4[1], V2.mean = mean(x$V2), + V3.mean = mean(x$V3), n = length(x$V1)) do.call(rbind, by(DF, DF[c(1,4)], fb)) V1 V4 V2.mean V3.mean n [1,] 1 1 2.0 400 3 [2,] 3 1 5.0 70 1 [3,] 2 2 0.7 35 2 # package doBy library(doBy) summaryBy(V2 + V3 ~ V1 + V4, DF, FUN = c(mean, length))[,-5] V1 V4 mean.V2 mean.V3 length.V3 1 A ID1 2.0 400 3 2 C ID1 5.0 70 1 3 B ID2 0.7 35 2 # package reshape library(reshape) f - function(x) c(mean = mean(x), n = length(x)) cast(melt(DF, id = c(1,4)), V1 + V4 ~ variable, fun.aggregate = f)[,-6] V1 V4 V2_mean V2_n V3_mean 1 A ID1 2.03 400 2 B ID2 0.72 35 3 C ID1 5.01 70 --- library(doBy) summaryBy(V2 + V3 ~ V1 + V4, DF, FUN = c(mean, length))[,-5] V1 V4 mean.V2 mean.V3 length.V3 1 A ID1 2.0 400 3 2 C ID1 5.0 70 1 3 B ID2 0.7 35 2 library(reshape) f - function(x) c(mean = mean(x), n = length(x)) cast(melt(DF, id = c(1,4)), V1 + V4 ~ variable, fun.aggregate = f)[,-6] V1 V4 V2_mean V2_n V3_mean 1 A ID1 2.03 400 2 B ID2 0.72 35 3 C ID1 5.01 70 On 9/14/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Thanks Gabor, that is much faster than using a loop! I've got a last question: Can you think of a fast way of keeping track of the number of observations collapsed for each entry? i.e. I'd like to end up with: A 2.0 400 ID1 3 (3obs in the first matrix) B 0.7 35 ID2 2 (2obs in the first matrix) C 5.0 70 ID1 1 (1obs in the first matrix) Or is it required to use an temporary matrix that is merged later? (As examplified by Mark in a previous email?) Thanks a lot for your help, Emmanuel On 9/13/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See below. On 9/13/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Thanks for pointing me out aggregate, that works fine! There is one complication though: I have mixed types (numerical and character), So the matrix is of the form: A 1.0 200 ID1 A 3.0 800 ID1 A 2.0 200 ID1 B 0.5 20 ID2 B 0.9 50 ID2 C 5.0 70 ID1 One letter always has the same ID but one ID can be shared by many letters (like ID1) I just want to keep track of the ID, and get a matrix like: A 2.0 400 ID1 B 0.7 35 ID2 C 5.0 70 ID1 Any idea on how to do that without a loop? If V4 is a function of V1 then you can aggregate by it too and it will appear but have no effect on the classification: aggregate(DF[2:3], DF[c(1,4)], mean) V1 V4 V2 V3 1 A ID1 2.0 400 2 C ID1 5.0 70 3 B ID2 0.7 35 Many thanks, Emmanuel On 9/12/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort
[R] Histogram of data with categorical varialbe
Hello, I have the following data: Km Sex 250 1 300 2 290 2 600 1 450 2 650 1 . I would like to obtain one histogram where the data (or the part) of each sex is visible, it is like cumulative histogram or spinogram. To be more comprehensible, i would like to know if the following graph is obtainable easily in R. It is the first graph on page 5 in the following document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] group bunch of lines in a data.frame, an additional requirement
Good idea. You could write it compactly like this: transform(aggregate(cbind(DF[2:3], o = 1), DF[c(1,4)], sum, na.rm = TRUE), + V2 = V2/o, V3 = V3/o) V1 V4 V2 V3 o 1 A ID1 2.0 400 3 2 B ID2 0.7 35 2 3 C ID3 5.0 70 1 On 9/15/06, Emmanuel Levy [EMAIL PROTECTED] wrote: (re)-Hello I actually thought about another possibility with a 1 column, a sum (instead of a mean), and a division of the columns for which I want the mean: DF = data.frame( V1=c(A,A,A,B,B,C) , V2=c(1,3,2,0.5,0.9,5.0), V3=c(200,800,200,20,50,70), V4=c(ID1,ID1,ID1,ID2,ID2,ID3)) DF2 = cbind(DF,o=rep(1,length(DF[,1]))) DF3 = aggregate(DF2[,c(2,3,5)], data.frame(code=DF2[,1],id=DF2[,4]), sum, na.rm=T) DF3[,3:4]=DF3[,3:4]/DF3[,5] DF3 code id V2 V3 o 1A ID1 2.0 400 3 2B ID2 0.7 35 2 3C ID3 5.0 70 1 Thanks again, Best, Emmanuel On 9/15/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Dear Mark, dear Gabor, Thanks again for your help! It is great to be able to get answers when no-one (can you believe this?) uses R in your lab. The package doBy looks really convenient for many puposes. Best, Emmanuel On 9/15/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: Here are three different ways to do it: # base R fb - function(x) c(V1 = x$V1[1], V4 = x$V4[1], V2.mean = mean(x$V2), V3.mean = mean(x$V3), n = length(x$V1)) do.call(rbind, by(DF, DF[c(1,4)], fb)) # package doBy library(doBy) summaryBy(V2 + V3 ~ V1 + V4, DF, FUN = c(mean, length))[,-5] # package reshape library(reshape) f - function(x) c(mean = mean(x), n = length(x)) cast(melt(DF, id = c(1,4)), V1 + V4 ~ variable, fun.aggregate = f)[,-6] # base R fb - function(x) +c(V1 = x$V1[1], V4 = x$V4[1], V2.mean = mean(x$V2), + V3.mean = mean(x$V3), n = length(x$V1)) do.call(rbind, by(DF, DF[c(1,4)], fb)) V1 V4 V2.mean V3.mean n [1,] 1 1 2.0 400 3 [2,] 3 1 5.0 70 1 [3,] 2 2 0.7 35 2 # package doBy library(doBy) summaryBy(V2 + V3 ~ V1 + V4, DF, FUN = c(mean, length))[,-5] V1 V4 mean.V2 mean.V3 length.V3 1 A ID1 2.0 400 3 2 C ID1 5.0 70 1 3 B ID2 0.7 35 2 # package reshape library(reshape) f - function(x) c(mean = mean(x), n = length(x)) cast(melt(DF, id = c(1,4)), V1 + V4 ~ variable, fun.aggregate = f)[,-6] V1 V4 V2_mean V2_n V3_mean 1 A ID1 2.03 400 2 B ID2 0.72 35 3 C ID1 5.01 70 --- library(doBy) summaryBy(V2 + V3 ~ V1 + V4, DF, FUN = c(mean, length))[,-5] V1 V4 mean.V2 mean.V3 length.V3 1 A ID1 2.0 400 3 2 C ID1 5.0 70 1 3 B ID2 0.7 35 2 library(reshape) f - function(x) c(mean = mean(x), n = length(x)) cast(melt(DF, id = c(1,4)), V1 + V4 ~ variable, fun.aggregate = f)[,-6] V1 V4 V2_mean V2_n V3_mean 1 A ID1 2.03 400 2 B ID2 0.72 35 3 C ID1 5.01 70 On 9/14/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Thanks Gabor, that is much faster than using a loop! I've got a last question: Can you think of a fast way of keeping track of the number of observations collapsed for each entry? i.e. I'd like to end up with: A 2.0 400 ID1 3 (3obs in the first matrix) B 0.7 35 ID2 2 (2obs in the first matrix) C 5.0 70 ID1 1 (1obs in the first matrix) Or is it required to use an temporary matrix that is merged later? (As examplified by Mark in a previous email?) Thanks a lot for your help, Emmanuel On 9/13/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: See below. On 9/13/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Thanks for pointing me out aggregate, that works fine! There is one complication though: I have mixed types (numerical and character), So the matrix is of the form: A 1.0 200 ID1 A 3.0 800 ID1 A 2.0 200 ID1 B 0.5 20 ID2 B 0.9 50 ID2 C 5.0 70 ID1 One letter always has the same ID but one ID can be shared by many letters (like ID1) I just want to keep track of the ID, and get a matrix like: A 2.0 400 ID1 B 0.7 35 ID2 C 5.0 70 ID1 Any idea on how to do that without a loop? If V4 is a function of V1 then you can aggregate by it too and it will appear but have no effect on the classification: aggregate(DF[2:3], DF[c(1,4)], mean) V1 V4 V2 V3 1 A ID1 2.0 400 2 C ID1 5.0 70 3 B ID2 0.7 35 Many thanks, Emmanuel On 9/12/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Hello, I'd like to group the
Re: [R] missing data codes
David Barron wrote: You've not given us much information to go on! Have you tried help(aregImpute,package=Hmisc) And for that sample size you'll have to tell aregImpute to force all continuous variables to act linearly Frank On 15/09/06, Qiong Wang [EMAIL PROTECTED] wrote: Dear all, I am new to R. I wish to use R's multiple imputation to deal with missing data. I have a data set with the size around 300 observations and 150 variables. I checked the help function in R and could not locate how to write the codes for this. can anyone give a hand? Do appreciate your time and kindness! Q. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Dear FE Harrell How can I get rreport ?
Anupam Tyagi wrote: justin bem justin_bem at yahoo.fr writes: Mr Harrell, After reading discussion about R output and SAS output , I will like to use rreport package. I a windows XP user Sincerly See: http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/Rreport Anupam. rreport has not been put in a package but all the source code is available on a per-function basis in our online cvs repository. What is really lacking is documentation but there is a detailed example on the above web site. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Histogram of data with categorical varialbe
Alexandre Depire wrote: Hello, I have the following data: Km Sex 250 1 300 2 290 2 600 1 450 2 650 1 . I would like to obtain one histogram where the data (or the part) of each sex is visible, it is like cumulative histogram or spinogram. To be more comprehensible, i would like to know if the following graph is obtainable easily in R. It is the first graph on page 5 in the following document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf Something like : d - data.frame( x = rnorm(100), sex = sample(c(1,2), replace=TRUE, size=100)) out - hist(d$x, col=gray) hist(d$x[d$sex==2], col=red, add=T, breaks=out$breaks) legend(topleft, c(male,female) , fill=c(gray,red)) box() Cheers, Romain -- *mangosolutions* /data analysis that delivers/ Tel +44 1249 467 467 Fax +44 1249 467 468 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: R Reference Card and other help (especially useful for Newbies)
Hi all: Newbies (and others!) may find useful the R Reference Card made available by Tom Short of EPRI Solutions at http://www.rpad.org/Rpad/Rpad-refcard.pdf or through the Contributed link on CRAN (where some other reference cards are also linked). It categorizes and organizes a bunch of R's basic, most used functions so that they can be easily found. For example, paste() is under the Strings heading and expand.grid() is under Data Creation. For newbies struggling to find the right R function as well as veterans who can't quite remember the function name, it's very handy. Also don't forget R's other Help facilties: help.search(keyword or phrase) to search the **installed** man pages RSiteSearch(keyword or phrase) to search the CRAN website via Jonathan Baron's search engine. This can also be done directly from CRAN by following the search link there. And, occasionally, find()/apropos() to search the ** attached** packages for functions using regexp's. Though R certainly can be intimidating, please **do** try these measures first before posting questions to the list. And please **do** read the other basic R reference materials. Better and faster answers can often be found this way. -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Histogram of data with categorical varialbe
On Fri, 15 Sep 2006 16:45:31 +0200 Alexandre Depire wrote: Hello, I have the following data: Km Sex 250 1 300 2 290 2 600 1 450 2 650 1 . I would like to obtain one histogram where the data (or the part) of each sex is visible, it is like cumulative histogram or spinogram. To be more comprehensible, i would like to know if the following graph is obtainable easily in R. It is the first graph on page 5 in the following document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf I think it's not available out of the box, but you can easily generate this yourself. Using the space shuttle o-ring data as an example (see also ?spineplot): fail - factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1), levels = c(1, 2), labels = c(no, yes)) temperature - c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70, 70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81) The you can do the following: ## generate unconditional histogram of numeric variable P(x) col - gray.colors(2) ht - hist(temperature, freq = FALSE, col = col[2]) ## using the same breaks, compute the conditional histogram P(x|group) br - ht$breaks ht2 - hist(temperature[fail == yes], plot = FALSE, freq = FALSE, breaks = br) ## and then add the rectangles using the joint densities ## P(x group) = P(x|group) * P(group) rect(br[-length(br)], 0, br[-1], ht2$density * mean(fail == yes), col = col[1]) Furthermore, you can take a look at the iplots package which should provide an interactive approach to this. Z [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Formula aruguments with NLS and model.frame()
I could use some help understanding how nls parses the formula argument to a model.frame and estimates the model. I am trying to utilize the functionality of the nls formula argument to modify garchFit() to handle other variables in the mean equation besides just an arma(u,v) specification. My nonlinear model is y-nls(t~a*sin(w*2*pi/365*id+p)+b*id+int,data=t1, start=list(w=.5,a=.1,p=.5,b=init.y$coef[2],int=init.y$coef[1] ), control=list(maxiter=100,minFactor=1e-18)) where t is change in daily temperatures, id is just a time trend and the a*sin is a one year fourier series. I have tried to debug the nls code using the following code t1-data.frame(t=as.vector(x),id=index(x)) data=t1; formula - as.formula(t ~ a *sin(w *2* pi/365 * id + p) + b * id + int); varNames - all.vars(formula) algorithm-'default'; mf - match.call(definition=nls,expand.dots=FALSE, call('nls',formula, data=parent.frame(),start,control = nls.control(), algorithm = default, trace = FALSE, subset, weights, na.action, model = FALSE, lower = -Inf, upper = Inf)); mWeights-F;#missing(weights); start=list(w=.5,a=.1,p=.5,b=init.y$coef[2],int=init.y$coef[1] ); pnames - names(start); varNames - varNames[is.na(match(varNames, pnames, nomatch = NA))] varIndex - sapply(varNames, function(varName, data, respLength) { length(eval(as.name(varName), data))%%respLength == 0}, data, length(eval(formula[[2]], data)) ); mf$formula - as.formula(paste(~, paste(varNames[varIndex], collapse = +)), env = environment(formula)); mf$start - NULL;mf$control - NULL;mf$algorithm - NULL; mf$trace - NULL;mf$model - NULL; mf$lower - NULL;mf$upper - NULL; mf[[1]] - as.name(model.frame); mf-evalq(mf,data); n-nrow(mf) mf-as.list(mf); wts - if (!mWeights) model.weights(mf) else rep(1, n) if (any(wts 0 | is.na(wts))) stop(missing or negative weights not allowed) m - switch(algorithm, plinear = nlsModel.plinear(formula, mf, start, wts), port = nlsModel(formula, mf, start, wts, upper), nlsModel(formula, mf, start, wts)); I am struggling with the environment issues associated with performing these operations. I did not include the data because it is 9000 observations of temperature data. If anyone would like the data, I can provide it or a subset in a csv file. thank you Joe __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Grouping columns in a data frame based on the values of a column
Dear R users, This is a trivial question, there might even be an R function for it, but I have to do it many times and wonder if there is an efficient for it. Suppose we have a data frame like this: d - data.frame(x=sample(seq(0.1:1, by=0.01), size=100, replace=TRUE), y=rnorm(100, 0.2, 0.6)) and want to have the average of y for a given interval of x, for example mean(y)[0x0.1]. Is there a simple way of doing this or I need to improvise? Thank you so much for any help Eleni Rapsomaniki __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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: Grouping columns in a data frame based on the values of a column
Perhaps using 'ave' and 'cut': df - data.frame(x=runif(100, 0.1, 1), y=rnorm(100, 0.2, 0.6)) df$xcut-cut(df$x, seq(0, 1, 0.1)) df$z-ave(df$y, df$xcut) df[order(df$x),] Stefano -Messaggio originale- Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] conto di [EMAIL PROTECTED] Inviato: venerdì 15 settembre 2006 17.45 A: r-help@stat.math.ethz.ch Oggetto: [R] Grouping columns in a data frame based on the values of a column Dear R users, This is a trivial question, there might even be an R function for it, but I have to do it many times and wonder if there is an efficient for it. Suppose we have a data frame like this: d - data.frame(x=sample(seq(0.1:1, by=0.01), size=100, replace=TRUE), y=rnorm(100, 0.2, 0.6)) and want to have the average of y for a given interval of x, for example mean(y)[0x0.1]. Is there a simple way of doing this or I need to improvise? Thank you so much for any help Eleni Rapsomaniki __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] question about pairs observations
Hi, I would like to paired ID_ with Cod for analysis in spdep. Any ideas? head(bai$att.data) ID_ NAME1_ NAME2_ PARTS_ POINTS_ LENGTH_ AREA_ 1 410690205001 410690205001 NA 1 158 5.243338 1.2668820 2 410690205009 410690205009 NA 1 159 6.071286 1.8409600 3 410690205026 410690205026 NA 1 108 3.955380 0.8876151 4 410690205027 410690205027 NA 1 251 6.747801 2.2430790 5 410690205041 410690205041 NA 1 243 7.314878 2.3123150 6 410690205042 410690205042 NA 1 269 5.405646 1.4390610 head(att.data) Codbairro alunos resid 1 410690205050 Abranches 33 11165 2 410690205014 Ahu 58 11148 3 410690205064Alto Boqueirao 36 51155 4 410690205004 Alto da Gloria 23 5588 5 410690205005Alto da Rua XV 48 8683 6 410690205055 Atuba 11 12632 Thanks! Bruno G. M. Churata __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] prediction interval for new value
Hi, 1. How do I construct 95% prediction interval for new x values, for example - x = 3? 2. How do I construct 95% confidence interval? my dataframe is as follows : dt structure(list(y = c(2610, 6050, 1620, 3070, 7010, 5770, 4670, 860, 1000, 6180, 3020, 5220, 7190, 5500, 1270 ), x = c(108000, 136000, 35000, 77000, 178000, 15, 126000, 24000, 28000, 214000, 108000, 19, 308000, 252000, 71000)), .Names = c(y, x), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) my regression eqn is as below: s.lm - lm(y ~ x) Thanks in advance. - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dotplot, dropping unused levels of 'y'
In dotplot, what's the best way to suppress the unused levels of 'y' on a per-panel basis? This is useful for the case that 'y' is a factor taking perhaps thousands of levels, but for a given panel, only a handfull of these levels ever present. Thanks, Ben __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] prediction interval for new value
predict(s.lm,data.frame(x=3),interval=prediction) fit lwr upr [1,] 16073985 -9981352 42129323 predict(s.lm,data.frame(x=3),interval=confidence) fit lwr upr [1,] 16073985 5978125 26169846 On 15/09/06, Sachin J [EMAIL PROTECTED] wrote: Hi, 1. How do I construct 95% prediction interval for new x values, for example - x = 3? 2. How do I construct 95% confidence interval? my dataframe is as follows : dt structure(list(y = c(2610, 6050, 1620, 3070, 7010, 5770, 4670, 860, 1000, 6180, 3020, 5220, 7190, 5500, 1270 ), x = c(108000, 136000, 35000, 77000, 178000, 15, 126000, 24000, 28000, 214000, 108000, 19, 308000, 252000, 71000)), .Names = c(y, x), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) my regression eqn is as below: s.lm - lm(y ~ x) Thanks in advance. - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dotplot, dropping unused levels of 'y'
Benjamin Tyner said the following on 9/15/2006 2:36 PM: In dotplot, what's the best way to suppress the unused levels of 'y' on a per-panel basis? This is useful for the case that 'y' is a factor taking perhaps thousands of levels, but for a given panel, only a handfull of these levels ever present. Thanks, Ben __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Hi, Ben, Use scales(x = list(relation = free)) in your call to dotplot: library(lattice) z - data.frame(x = rep(LETTERS[1:20], each = 4), y = 1:80, g = gl(4, 20)) dotplot(y ~ x | g, z, scales = list(x = list(relation = free))) HTH, --sundar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Question about span in Loess function
Hi, I want to do 2-dimentional loess smoothing in gam through the command gam(Y~lo(X1,X2,span=span,degree=1) ) in library gam. The span is the percentage of data points to define the neighborhood and used for the smoothing. Does this command do one 2-dimentional smoothing with neighboring defined according to the radius of the data point || X=(X1,X2) ||, or it does two 1-dimentional smoothing which smooths X1, X2 separately? I'm actually doing spatial smoothing with longitude and latitude, so I need the 2-dimentional smoothing so the results won't depend on the coordinate values. Thanks a lot!!! Best, Yijie Zhou [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] prediction interval for new value
David, Thanks for the quick reply. Just confirming, does predict(s.lm,data.frame(x=3),interval=prediction) gives prediction interval or tolerance interval? Thanks Sachin David Barron [EMAIL PROTECTED] wrote: predict(s.lm,data.frame(x=3),interval=prediction) fit lwr upr [1,] 16073985 -9981352 42129323 predict(s.lm,data.frame(x=3),interval=confidence) fit lwr upr [1,] 16073985 5978125 26169846 On 15/09/06, Sachin J [EMAIL PROTECTED] wrote: Hi, 1. How do I construct 95% prediction interval for new x values, for example - x = 3? 2. How do I construct 95% confidence interval? my dataframe is as follows : dt structure(list(y = c(2610, 6050, 1620, 3070, 7010, 5770, 4670, 860, 1000, 6180, 3020, 5220, 7190, 5500, 1270 ), x = c(108000, 136000, 35000, 77000, 178000, 15, 126000, 24000, 28000, 214000, 108000, 19, 308000, 252000, 71000)), .Names = c(y, x), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) my regression eqn is as below: s.lm - lm(y ~ x) Thanks in advance. - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP - [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] dotplot, dropping unused levels of 'y'
On 9/15/06, Benjamin Tyner [EMAIL PROTECTED] wrote: In dotplot, what's the best way to suppress the unused levels of 'y' on a per-panel basis? This is useful for the case that 'y' is a factor taking perhaps thousands of levels, but for a given panel, only a handfull of these levels ever present. It's a bit problematic. Basically, you can use relation=free/sliced, but y behaves as as.numeric(y) would. So, if the small subset in each panel are always more or less contiguous (in terms of the levels being close to each other) then you would be fine. Otherwise you would not. In that case, you can still write your own prepanel and panel functions, e.g.: - library(lattice) y - factor(sample(1:100), levels = 1:100) x - 1:100 a - gl(9, 1, 100) dotplot(y ~ x | a) p - dotplot(y ~ x | a, scales = list(y = list(relation = free, rot = 0)), prepanel = function(x, y, ...) { yy - y[, drop = TRUE] list(ylim = levels(yy), yat = sort(unique(as.numeric(yy }, panel = function(x, y, ...) { yy - y[, drop = TRUE] panel.dotplot(x, yy, ...) }) -- Hope that gives you what you want. Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 truncated distribution
I resend this to expect more responses. Thanks! Inspired by the responses, I tried to do this analytically. The idea is that truncated mean and standard deviation could be expressed as integral forms. So if given truncated mean, sd and truncated point (mut, sdt, thre), an optim( ) function could be writen to get the parameters. But the problem is, pdf is needed in advance to shape the normal curve. So I think it is possible to do this in an iterative optimization, given assummed initial sigma and mu, if the optimization meets requirements, then the sigma and mu could be considered as the real numbers. I tried to do these by : f - function(x,sigma,mu) (1/(sigma*sqrt(2*pi)))*exp(-(x-mu)^2/(2*sigma^2)) pdf.fun - function(x) x*f(x); sd.fun - function(x) x^2*f(x); #-- define a few functions solve.fun - function(sigma,mu,thre,mut,sdt) { (mut-integrate(pdf.fun,thre,upper=Inf)$value/integrate(f,thre,upper=Inf)$value)^2 +(sdt - integrate(sd.fun,thre,upper=Inf)$value/integrate(f,thre,upper=Inf)$value-(integrate(pdf.fun,thre,upper=Inf)$value/integrate(f,thre,upper=Inf)$value)^2)^2 } I wish this solve.fun ( ) could be minimized and then gives minimum = 5 for( i in 1:100) { mu - 200;sigma - 20; thre - 160; mut - 230; sdt - 15; sol.tem - optimize(solve.fun, lower =0.1,upper =100,tol=0.001); if (sol.tem$minimum = 5) return(sol.tem) } I know my codes is just awkward, and not really working. But I expect some advice and suggestion about the methods. Am I going in a wrong way since I have been working on it for a long time. Thanks a lot! Jen -Original Message- From:Ritwik Sinha , [EMAIL PROTECTED] Sent: 2006-09-12, 17:20:04 To: CC:jennystadt; r-help@stat.math.ethz.ch Subject: Re: [R] About truncated distribution However, if you know the point(s) of truncation then you should be able to work your way back. Look for the mean and variance of a truncated normal, it will involve mu, sigma and c (point of truncation). You will need to solve for mu and sigma from two equation. For example look at the wikipedia page on normal distribution, it has the mean of a truncated normal distribution. Many standard statistics books should have the rest of the information. On 9/12/06, Berton Gunter [EMAIL PROTECTED] wrote: But my question is a bit different. What I know is the mean and sd after truncation. If I assume the distribution is normal, how I am gonna develope the original distribution using this two parameters? You can't, as they are plainly not sufficient (you need to know the amount of truncation also). If you have only the mean and sd and neither the actual data nor the truncation point you're through. -- Bert Gunter Genentech Could anybody give me some advice? Thanks in advance! Jen [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Trouble installing modified package
I am updating the CRAN package LMGene, and I'm having trouble installing the new version. I changed the working package name to WLMG so I could use the new version without removing the old version from the R directory. I set up R_LIBS to allow installation in a different directory. When I did R CMD INSTALL -l /linux-ws/tilling/Rlib WLMG it put the right files in the right place. However, when I went into R and typed library(WLMG), it fails with the message Error in library(WLMG) : there is no package called 'WLMG' The obvious things: .libPaths already has the directory, since I put it in the Unix R_LIBS variable: .libPaths() [1] /home/tilling/Rlib /usr/lib64/R/library I also changed the package name in the DESCRIPTION file to WLMG. Does anyone have a guess what's going on? What else might need fixing? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Rpart, custom penalty for an error
On Sun, 2006-09-10 at 20:36 +0100, Prof Brian Ripley wrote: I am however interested in areas where the probability of success is noticeably higher than 5%, for example 20%. I've tried rpart and the weights option, increasing the weights of the success-observations. You are 'misleading' rpart by using 'weights', claiming to have case weights for cases you do not have. You need to use 'cost' instead. As for the rpart() function, the `cost' parameter is for scaling the variables, not for the cost of misclassifications. To specify it, the parameter `parms' needs to be used, as a list with a `loss' element, in form of a matrix. In other words, cost parm is not for cost, use loss parm of the parms parm. Example usage: tr - rpart(y ~ x, data = some.data, method = 'class', parms = list(loss = matrix(c(0, 1, 20, 0), nrow = 2))) This is a standard issue, discussed in all good books on classification (including mine). Yes, in MASS, section 12.2, Classification Theory, page 338 (fourth edition). I was looking for it in section 9.2, where rpart() is discussed. Thanks! Regards, Maciej -- http://automatthias.wordpress.com __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Periodogram of Schuster
Dear All, Is there a function in R which can do a periodogram of Schuster ? Thanks in advance ! Guillaume Blanchet __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] LARS for generalized linear models
Hi, Is there an R implementation of least angle regression for binary response modeling? I know that this question has been asked before, and I am also aware of the lasso2 package, but that only implements an L1 penalty, i.e. the Lasso approach. Madigan and Ridgeway in their discussion of Efron et al (2004) describe a LARS-type algorithm for generalized linear models. Has anyone implemented this in R? Thanks for any help. Best, Ravi --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] LARS for generalized linear models
On Fri, 2006-09-15 at 18:49 -0400, Ravi Varadhan wrote: Hi, Is there an R implementation of least angle regression for binary response modeling? I know that this question has been asked before, and I am also aware of the lasso2 package, but that only implements an L1 penalty, i.e. the Lasso approach. Madigan and Ridgeway in their discussion of Efron et al (2004) describe a LARS-type algorithm for generalized linear models. Has anyone implemented this in R? Thanks for any help. Best, Ravi This just came up last month. See this post: https://stat.ethz.ch/pipermail/r-help/2006-August/111352.html HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] regarding chaos
hi all, I have a simple question that does power spectral analysis related to capacity dimension, information dimension, lyapunov exponent, hurst exponent. If yes then please show me the way. I am newbie in the world of chaos. Sayonara With Smile With Warm Regards :-) G a u r a v Y a d a v Senior Executive Officer, Economic Research Surveillance Department, Clearing Corporation Of India Limited. Address: 5th, 6th, 7th Floor, Trade Wing 'C', Kamala City, S.B. Marg, Mumbai - 400 013 Telephone(Office): - +91 022 6663 9398 , Mobile(Personal) (0)9821286118 Email(Office) :- [EMAIL PROTECTED] , Email(Personal) :- [EMAIL PROTECTED] DISCLAIMER AND CONFIDENTIALITY CAUTION:\ \ This message and ...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.