KEMBAR78
Chi-Square Test | PDF | Correlation And Dependence | Scientific Method
0% found this document useful (0 votes)
34 views4 pages

Chi-Square Test

The document discusses different correlation tests including Pearson, Spearman, and Kendall correlations. It calculates correlations between variables in the state.x77 dataset and displays the results.

Uploaded by

Sunil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

Chi-Square Test

The document discusses different correlation tests including Pearson, Spearman, and Kendall correlations. It calculates correlations between variables in the state.x77 dataset and displays the results.

Uploaded by

Sunil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CHI-SQUARE TEST

#chi-square test

install.packages("vcd")

library(vcd)

#Chi-Square test

View(Arthritis)

mytable1<-xtabs(~Treatment+Improved,data=Arthritis)

mytable1

chisq.test(mytable1)

mytable2<-xtabs(~Improved+Sex,data=Arthritis)

mytable2

chisq.test(mytable2)

OUTPUT

#Chi-Square test

> View(Arthritis)

> mytable1<-xtabs(~Treatment+Improved,data=Arthritis)

> mytable1

Improved

Treatment None Some Marked

Placebo 29 7 7

Treated 13 7 21

> chisq.test(mytable1)

Pearson's Chi-squared test

data: mytable1

X-squared = 13.055, df = 2, p-value = 0.001463


> mytable2<-xtabs(~Improved+Sex,data=Arthritis)

> mytable2

Sex

Improved Female Male

None 25 17

Some 12 2

Marked 22 6

CORRELATION

# Correlation

#Correlation coefficients are used to describe relationships among quantitative variables. The sign ±
indicates the direction of the relationship (positive or inverse) and

#the magnitude indicates the strength of the relationship (ranging from 0 for no relationship to 1 for a
perfectly predictable relationship)

#PEARSON, SPEARMAN, AND KENDALL CORRELATIONS

#The Pearson product moment correlation assesses the degree of linear relationship

#between two quantitative variables.

#Spearman's Rank Order correlation coefficient assesses the degree of relationship between two rank-
ordered variables.

#Kendall's Tau is also a nonparametric measure of rank correlation.

#cor(x,use=,method=)

states<-state.x77[,1:6]

View(states)

cor(states)

cor(states,method="spearman")

cor(states,method="kendall")
x <- states[,c("Population", "Income", "Illiteracy", "HS Grad")]

y <- states[,c("Life Exp", "Murder")]

cor(x,y)

Output

# Correlation

> #Correlation coefficients are used to describe relationships among quantitative variables. The sign ±
indicates the direction of the .... [TRUNCATED]

> View(states)

> cor(states)

Population Income Illiteracy Life Exp Murder HS Grad

Population 1.00000000 0.2082276 0.1076224 -0.06805195 0.3436428 -0.09848975

Income 0.20822756 1.0000000 -0.4370752 0.34025534 -0.2300776 0.61993232

Illiteracy 0.10762237 -0.4370752 1.0000000 -0.58847793 0.7029752 -0.65718861

Life Exp -0.06805195 0.3402553 -0.5884779 1.00000000 -0.7808458 0.58221620

Murder 0.34364275 -0.2300776 0.7029752 -0.78084575 1.0000000 -0.48797102

HS Grad -0.09848975 0.6199323 -0.6571886 0.58221620 -0.4879710 1.00000000

> cor(states,method="spearman")

Population Income Illiteracy Life Exp Murder HS Grad

Population 1.0000000 0.1246098 0.3130496 -0.1040171 0.3457401 -0.3833649

Income 0.1246098 1.0000000 -0.3145948 0.3241050 -0.2174623 0.5104809

Illiteracy 0.3130496 -0.3145948 1.0000000 -0.5553735 0.6723592 -0.6545396

Life Exp -0.1040171 0.3241050 -0.5553735 1.0000000 -0.7802406 0.5239410

Murder 0.3457401 -0.2174623 0.6723592 -0.7802406 1.0000000 -0.4367330

HS Grad -0.3833649 0.5104809 -0.6545396 0.5239410 -0.4367330 1.0000000

> cor(states,method="kendall")

Population Income Illiteracy Life Exp Murder HS Grad


Population 1.00000000 0.08408163 0.2123063 -0.06865555 0.2364983 -0.2353905

Income 0.08408163 1.00000000 -0.1970811 0.21904389 -0.1448450 0.3579896

Illiteracy 0.21230629 -0.19708113 1.0000000 -0.42852098 0.5155359 -0.5047401

Life Exp -0.06865555 0.21904389 -0.4285210 1.00000000 -0.5997547 0.3952537

Murder 0.23649826 -0.14484495 0.5155359 -0.59975465 1.0000000 -0.2884066

HS Grad -0.23539045 0.35798964 -0.5047401 0.39525368 -0.2884066 1.0000000

> x <- states[,c("Population", "Income", "Illiteracy", "HS Grad")]

> y <- states[,c("Life Exp", "Murder")]

> cor(x,y)

Life Exp Murder

Population -0.06805195 0.3436428

Income 0.34025534 -0.2300776

Illiteracy -0.58847793 0.7029752

HS Grad 0.58221620 -0.4879710

You might also like