Why am I getting a wrong result for quartiles?
here is my code: > cbiomass = c(910, 1058, 929, 1103, 1056, 1022, 1255, 1121, 1111, 1192, 1074, 1415) > summary(cbiomass) > IQR(cbiomass) The result R gives me is: For the summary > Min. 1st Qu. Median Mean 3rd Qu. Max. 910 1048 1088 1104 1139 1415 For IQR > 91.25 ********* The true Q1 is 1039 and not 1048. Q2 is 1156.5 and not 1139. And the Inter-Quartile Range is 117.5 and not 91.25 How can I get these number right? |
It's looks like you think that type=2 are the 'true' quantiles, but the default method in R is type=7
You might want to look at ?stats::quantile hth david freedman |
Interestingly, Hmisc::describe() and summary() seem to be using one Type, and stats::fivenum() seems to be using another Type.
> fivenum(cbiomass) [1] 910.0 1039.0 1088.5 1156.5 1415.0 > summary(cbiomass) Min. 1st Qu. Median Mean 3rd Qu. Max. 910 1048 1088 1104 1139 1415 > describe(cbiomass)$counts n missing unique Mean .05 .10 .25 .50 .75 "12" "0" "12" "1104" " 920.5" " 938.3" "1047.5" "1088.5" "1138.8" .90 .95 "1248.7" "1327.0" cheers, -Girish |
and SAS give one a choice of 5 option, and i'm fairly sure that it used
a different default than does R (although one of the 5 corresponds to the sas default) see pctldef on http://www.technion.ac.il/docs/sas/proc/z0146803.htm my simple brain thinks of thinks of the problem as 'how does one calculate the median of 4 values?' david freedman Girish A.R. [via R] wrote: > Interestingly, Hmisc::describe() and summary() seem to be using one > Type, and stats::fivenum() seems to be using another Type. > > > fivenum(cbiomass) > [1] 910.0 1039.0 1088.5 1156.5 1415.0 > > summary(cbiomass) > Min. 1st Qu. Median Mean 3rd Qu. Max. > 910 1048 1088 1104 1139 1415 > > describe(cbiomass)$counts > n missing unique Mean .05 .10 .25 > .50 .75 > "12" "0" "12" "1104" " 920.5" " 938.3" "1047.5" > "1088.5" "1138.8" > .90 .95 > "1248.7" "1327.0" > > cheers, > -Girish > > View message @ > http://n4.nabble.com/Quartiles-and-Inter-Quartile-Range-tp1145817p1248728.html > > To unsubscribe from Re: Quartiles and Inter-Quartile Range, click here > <http://n4.nabble.com/subscriptions/Unsubscribe.jtp?code=My4xNGRhdmlkQGdtYWlsLmNvbXwxMjEzMTk5fDIwNzYxOTc1NTM=>. > > |
In reply to this post by David Freedman 2
Thank you David. I got it now.
Maybe you can help again. I am typing the following code to draw a QQ plot but the line does not look right? ******************* qqnorm(cbiomass) qqline(cbiomass) *********************** the graph looks very different from the graph generated by SAS. Thank you again. Emiliano. Date: Fri, 22 Jan 2010 21:32:26 -0800 From: [hidden email] To: [hidden email] Subject: Re: Quartiles and Inter-Quartile Range It's looks like you think that type=2 are the 'true' quantiles, but the default method in R is type=7 You might want to look at ?stats::quantile hth david freedman
View message @ http://n4.nabble.com/Quartiles-and-Inter-Quartile-Range-tp1145817p1213199.html
To unsubscribe from Quartiles and Inter-Quartile Range, click here. Quer fazer um álbum íncrivel? Conheça o Windows Live Fotos clicando aqui. |
please do some reading - I *think* the main difference is that the x and y axes are reversed, but I really don't know what SAS prints out
there are a many 'defaults' that are rather arbitrary - sometimes SAS uses 1, while R uses another ??qqnorm brings up a list of functions, including stats::qqnorm ?stats::qqnorm brings up the help page for the function On Mon, Jan 25, 2010 at 12:41 PM, eeramalho [via R] <[hidden email]> wrote: Thank you David. I got it now. -- Natalia and/or David |
In reply to this post by eeramalho
eeramalho wrote: > > Thank you David. I got it now. > > Maybe you can help again. > > I am typing the following code to draw a QQ plot but the line does not look right? > > ******************* > qqnorm(cbiomass) > > qqline(cbiomass) > *********************** > the graph looks very different from the graph generated by SAS. There are two possibilities: 1. you need to use the argument 'datax = TRUE' 2. SAS is wrong You might also have a look at the qq.plot() function in package 'car'. -Peter Ehlers > > Thank you again. > > Emiliano. > > Date: Fri, 22 Jan 2010 21:32:26 -0800 > From: [hidden email] > To: [hidden email] > Subject: Re: Quartiles and Inter-Quartile Range > > > > It's looks like you think that type=2 are the 'true' quantiles, but the default method in R is type=7 > > > You might want to look at ?stats::quantile > > > hth > > david freedman > > > > > > View message @ http://n4.nabble.com/Quartiles-and-Inter-Quartile-Range-tp1145817p1213199.html > > > To unsubscribe from Quartiles and Inter-Quartile Range, click here. > > > > _________________________________________________________________ > Sabia que você tem 25Gb de armazenamento grátis na web? Conheça o Skydrive agora. > > Live:produtoSkyDrive:Tagline:WLCRM:On:WL:pt-BR:SkyDrive > > > ------------------------------------------------------------------------ > > ______________________________________________ > [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. -- Peter Ehlers University of Calgary ______________________________________________ [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. |
Free forum by Nabble - Free Resume Builder | Edit this page |