R language: Common Statistics some method code

Source: Internet
Author: User

When theory is dependent on several unknown parameters
Kolmogorov-smirnov Review
Ks.test ()
For example, a two-device life review, recording 10 times without obstruction, and according to the order from small to large to the following,
Review the essentials with KS to review the equipment without prejudice to the timing of the rambda=1/1500 index diffuse
Called:
X<-C (420, 500, 920, 1380, 1510, 1650, 1760, 2100, 2300, 2350)
Ks.test (X, "Pexp", 1/1500)
Example two assumes that 25 and 20 survey values are randomly sampled from the population of the diffuse function f (x) and g (X) to review whether F (x) and g (x) communicate.
Called
X<-scan ()
0.61 0.29 0.06 0.59-1.73-0.74 0.51-0.56 0.39
1.64 0.05-0.06 0.64-0.82 0.37 1.77 1.09-1.28
2.36 1.31 1.05-0.32-0.40 1.06-2.47
Y<-scan ()
2.20 1.66 1.38 0.20 0.36 0.00 0.96 1.56 0.44
1.50-0.30 0.66 2.31 3.29-0.27-0.37 0.38 0.70
0.52-0.71
Ks.test (X, Y)
The scope of the KS multi-sample review is only used in the theory of diffuse to one-dimensional continuous diffuse, and diffuse fully known scene. KS Review available environment, function generally better than Pearson CHISQ review
Review of the independence of the list (contingerncy table)
Pearson Chisquare held Independence review
In order to study whether smoking is associated with lung cancer, the number of smokers in 63 patients and 43 non-lung cancer patients was observed, and the 2*2 list was obtained.
Data lung cancer healthy total
Smoking 60 32 92
Non-smoking 3 11 14
Total 63 43 106
Called
X<-c (60, 3, 32, 11)
Dim (x) <-c (2,2)
Chisq.test (X,correct = FALSE) # Environment without continuous correction
Chisq.test (x) # Environment with continuous correction
Example Four
In a social observation, the annual income of 901 people was observed by means of questionnaires, and the level of satisfaction for things was divided into four stalls: less than 6000 yuan, 6000-15000 yuan, 15000 yuan to 25000 yuan, and 25000 yuan higher. To the level of satisfaction of the things B is not satisfied, less satisfied, the foundation to meet and very satisfied with the four gears, the effectiveness of the following
Very unsatisfied less satisfied with the basic satisfaction is satisfied total
< 6000 20 24 80 82 206
6000 ~15000 22 38 104 125 289
15000 ~25000 13 28 81 113 235
> 25000 7 18 54 92 171
Total 62 108 319 412 901
Call for the following
X<-scan ()
20 24 80 82 22 38 104 125
13 28 81 113 7 18 54 92
Dim (x) <-c (bis)
Chisq.test (x)
Fisher's more accurate independent review
Trial condition sample number less than 4
Example Five
A physician study of hepatitis B immunization ball protein to prevent intrauterine fetal infection of HBV results, 33 cases of HBSAG positive pregnant women randomly divided into the prevention of injection group and comparison group, the efficacy by the following table, the two groups of newborns, the overall rate of HBV infection is not different
Group positive negative total infection rate
Prevention of Injection Group 4 18 22 18.8
Comparison Group 5 6 11 45.5
Call for the following
X<-c (4,5,18,6); Dim (x) <-c (2,2)
Fisher.test (x)
Review of the aforementioned lung cancer organization
X<-c (60, 3, 32, 11); Dim (x) <-c (2,2)
Fisher.test (x)
McNemar Review
McNemar Review is not an independent review, but a review of the list
Example VI
The efficacy of two kinds of essentials to detect bacteria
B Essentials
Total
Nail Essentials +-
+ 49 25 74
-21 107 128
Total 70 132 202
Called
X<-c (49, 21, 25, 107); Dim (X) <-c (2,2)
Mcnemar.test (X,correct=false)
Mark Review
1 Suppose a sample is from a population
Example VII
The number of people living in the 66 most likely life-consuming index (in New York in December 1996 to 100), and the number of vouchers from small to large are as follows, the index of Beijing is 99. Suppose this sample is obtained randomly from most of the world. The mark-up review stated that Beijing was above the median, as usual.
X<-scan ()
66 75 78 80 81 81 82 83 83 83 83
84 85 85 86 86 86 86 87 87 88 88
88 88 88 89 89 89 89 90 90 91 91
91 91 92 93 93 96 96 96 97 99 100
101 102 103 103 104 104 104 105 106 109 109
110 110 110 111 113 115 116 117 118 155 192
Binom.test (sum (x>99), Length (X), al= "L")
2 use of paired samples to review whether there is a difference between the two populations
Example VIII
Two kinds of differential feed, on the pig weight gain environment as follows, clarify two kinds of feed pig have no difference
Called
X<-scan ()
25 30 28 23 27 35 30 28 32 29 30 30 31 16
Y<-scan ()
19 32 21 19 25 31 31 26 30 25 28 31 25 25
Binom.test (sum (x<y), Length (x))
Example Nine
A beverage store for the observation of the employer's preferences for the environment, a day randomly observed 13 for the employer, like milk tea high out of coffee with-hint, like coffee high out of tea with + hint, both like to use 0 hint, the efficacy is as follows, stating that the employer is more like coffee start tea.
Employer Number 1 2 3 4 5 6 7 8 9 10 11 12 13
Like coffee 1 1 1 1 0 1 1 1 1 1
Like milk tea 1 1 1
Binom.test (3,12,P=1/2, al= "L", Conf.level = 0.90)
Rank statistics
Spearman Rank related review
Example Ten
A six-person participation in the performance of the competition, there are two people to conduct assessment, assessment of efficacy as shown in the table, trial Spearman rank related Review Essentials review the two inspectors to deal with the grade evaluation has no relevance
Contestant Number 1 2 3 4 5 6
A's score 4 2 2 4 5 6
B's score 5 3 4 3 2 5
X<-c (4,2,2,4,5,6); Y<-c (5,3,4,3,2,5)
Cor.test (x, y, method = "Spearman")
Kendall related Review
Example Xi.
A kindergarten on the intelligence of 9 pairs of twins to hold examinations, and the credentials percentile score, trial Kendall related review essentials to review the Twins intelligence is related.
1 2 3 4 5 6 7 8 9
86 77 68 91 70 71 85 87 63
88 76 64 96 65 80 81 72 60
X<-c (86, 77, 68, 91, 70, 71, 85, 87, 63)
Y&LT;-C (88, 76, 64, 96, 65, 80, 81, 72, 60)
Cor.test (X, Y, method = "Kendall")
Wilcoxon Rank review--consideration of the difference in the overall median month of the sample survey value.
1 against a review of the same overall sample
Example 12
A battery factory says it produces a battery that has a median of 140 ampere-hours, and is randomly extracting 20 of its newly produced batteries, reviewing its lifespan, 137.0 140.0 138.3 139.0 144.3 139.1 141.7 137.3 133.5 138.2 141.1 139.2 136.5 136.5 135.6 138.0 140.9 140.6 136.3 134.1
Using the Wilcoxon Mark Review to clarify whether the battery is suitable for the scale of the plant
X<-scan ()
137.0 140.0 138.3 139.0 144.3 139.1 141.7 137.3 133.5 138.2
141.1 139.2 136.5 136.5 135.6 138.0 140.9 140.6 136.3 134.1
Wilcox.test (X, mu=140, alternative= "less",
Exact=false, Correct=false, Conf.int=true)
This guideline can also be used adulthood to review the sample
Example 13
In order to review a new fertilizer, the existing wheat land is divided into 10 pieces, then divided into two departments, half of the common fertilizer, half new fertilizer, using Wilcoxon Mark Review method to review the new compound fertilizer can significantly improve wheat yield.
1 2 3 4 5 6 7 8 9 10
459 367 303 392 310 342 421 446 430 412
414 306 321 443 281 301 353 391 405 390

X<-c (459, 367, 303, 392, 310, 342, 421, 446, 430, 412)
Y<-c (414, 306, 321, 443, 281, 301, 353, 391, 405, 390)
Wilcox.test (x, y, alternative = "greater", paired = TRUE)
Wilcox.test (x-y, alternative = "greater")
Binom.test (sum (x>y), Length (x), alternative = "greater")
Ranking and review of non-paired samples
Wilcoxon-mann-whitney Statistics U
Example 14
The blood lead levels of 10 workers in different groups were measured, and the difference between the two group was clarified.
Non-lead Homework Group 24 26 29 34 43 58 63 72 87 101
Lead-containing homework group 82 87 97 121 164 208 213
X<-c (24, 26, 29, 34, 43, 58, 63, 72, 87, 101)
Y<-c (82, 87, 97, 121, 164, 208, 213)
Wilcox.test (x,y,alternative= "Less", Exact=false,correct=false)
Wilcox.test (x, y, alternative= "less", Exact=false)
Example XV
Students ' mathematical Skills in order
New Essentials 3 5 7 9 10
Original Essentials 1 2 4 6 8
New Essentials 4 6 7 9 10
Original Essentials 1 2 3 5 8
X<-c (3, 5, 7, 9, 10); Y<-c (1, 2, 4, 6, 8)
Wilcox.test (x, Y, alternative= "greater")

Example 16
A review of a drug to deal with chronic bronchitis has resulted in the extraction of 216 cases of treatment results. Clarify whether the drug is communicating with the outcome of the treatment of two chronic bronchitis.
Moderation and progress ineffective
Pure Type 62 41 14 11
Pant 20 37 16 15
X<-rep (1:4, C (62, 41, 14,11)); Y<-rep (1:4, C (20, 37, 16, 15))
Wilcox.test (x, y, Exact=false)

Turn from: https://uhomework.com/a/qitajiaocheng/20171204/9574.html genius writer

R language: Common Statistics some method code

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.