R language Notes functions for calculating descriptive statistics

Source: Internet
Author: User
Tags vars

These include Hmisc, pastecs and Psych. Because these packages are not included in the underlying installation.


> Library (HMISC)

> describe (mtcars[vars])

Mtcars[vars]


3 Variables Observations

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------

Mpg

N Missing unique Info Mean. 05.10.25.50.75.90.95

32 0 25 1 20.09 12.00 14.34 15.43 19.20 22.80 30.09 31.30


lowest:10.4 13.3 14.3 14.7 15.0, highest:26.0 27.3 30.4 32.4 33.9

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------

Hp

N Missing unique Info Mean. 05.10.25.50.75.90.95

32 0 22 1 146.7 63.65 66.00 96.50 123.00 180.00 243.50 253.55


lowest:52, highest:215 230 245 264 335

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------

Wt

N Missing unique Info Mean. 05.10.25.50.75.90.95

32 0 29 1 3.217 1.736 1.956 2.581 3.325 3.610 4.048 5.293


lowest:1.513 1.615 1.835 1.935 2.140, highest:3.845 4.070 5.250 5.345 5.424

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------

>


--------------------------------------------------------------------


The package has a function called STAT.DESC () that calculates a wide variety of descriptive statistics. Use

The format is:

> Stat.desc (mtcars[vars],basic=true,desc=true,norm=false,p=0.95)

where x is a data frame or time series. If Basic=true (default), all values, nulls, missing

The number of values, as well as the minimum, maximum, value, and sum. If Desc=true (also the default value), the calculation

Standard error of median, mean, mean, confidence interval, variance, standard deviation and variance system of average confidence of 95%

Number. Finally, if norm=true (not the default), the normal distribution statistic is returned, including skewness and kurtosis (and their

Statistical significance) and shapiro–wilk normal test results. The P-value is used to calculate the confidence interval of the average (the default

Confidence level is 0.95)

> Library (pastecs)

> Stat.desc (Mtcars[vars])

MPG HP WT

Nbr.val 32.0000000 32.0000000 32.0000000

Nbr.null 0.0000000 0.0000000 0.0000000

Nbr.na 0.0000000 0.0000000 0.0000000

Min 10.4000000 52.0000000 1.5130000

Max 33.9000000 335.0000000 5.4240000

Range 23.5000000 283.0000000 3.9110000

Sum 642.9000000 4694.0000000 102.9520000

Median 19.2000000 123.0000000 3.3250000

Mean 20.0906250 146.6875000 3.2172500

Se.mean 1.0654240 12.1203173 0.1729685

ci.mean.0.95 2.1729465 24.7195501 0.3527715

var 36.3241028 4700.8669355 0.9573790

Std.dev 6.0269481 68.5628685 0.9784574

Coef.var 0.2999881 0.4674077 0.3041285



------------------------------------------------

Library (Psych)

Describe (Mtcars[vars])

VARs n mean sd median trimmed mad min max range skew kurtosis se

MPG 1 32 20.09 6.03 19.20 19.70 5.41 10.40 33.90 23.50 0.61-0.37 1.07

HP 2 32 146.69 68.56 123.00 141.19 77.10 52.00 335.00 283.00 0.73-0.14 12.12

WT 3 32 3.22 0.98 3.33 3.15 0.77 1.51 5.42 3.91 0.42-0.02 0.17



In the previous example, a function named describe () is provided in both the psych package and the Hmisc package. How does R know the

Which one do you use? In short, the last loaded package takes precedence, as shown in Listing 7-5. Here, Psych in

Hmisc is then loaded, and a message is displayed indicating that the describe () function in the Hmisc package is psych

The function in the package with the same name is masked (masked). When you type describe (), R searches for this function first

To the function in the psych package and execute it. If you want to change the version in the Hmisc package, you can type

Hmisc::d escribe (MT). This function is still there. You just need to give r more information to find it


R language Notes functions for calculating descriptive statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.