This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
## correlations between the mean wvs value (jvmean) and the percentage of "always justifiable" (jv0) with rates of violence (violence)
correlation <- cor(data$violence, data$jv0)
correlation
## [1] 0.1266883
correlation <- cor(data$violence, data$jvmean)
correlation
## [1] 0.2218276
## scatterplot shows no patterns, so we try to test a non-linear relationship with a quadratic polynomial regression
lm_poly <- lm(jv0 ~ poly(violence, 2), data = data)
summary(lm_poly)
##
## Call:
## lm(formula = jv0 ~ poly(violence, 2), data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.7626 -2.4869 -0.5565 1.2595 11.9352
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.7729 0.8507 4.435 0.00023 ***
## poly(violence, 2)1 2.8771 4.1675 0.690 0.49753
## poly(violence, 2)2 11.9467 4.1675 2.867 0.00924 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.168 on 21 degrees of freedom
## Multiple R-squared: 0.2928, Adjusted R-squared: 0.2254
## F-statistic: 4.347 on 2 and 21 DF, p-value: 0.02632
lm_poly <- lm(jvmean ~ poly(violence, 2), data = data)
summary(lm_poly)
##
## Call:
## lm(formula = jvmean ~ poly(violence, 2), data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.0222 -0.5311 -0.2489 0.3395 2.0927
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.9483 0.1952 15.104 9.42e-13 ***
## poly(violence, 2)1 1.0534 0.9563 1.102 0.283
## poly(violence, 2)2 1.4951 0.9563 1.563 0.133
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.9563 on 21 degrees of freedom
## Multiple R-squared: 0.1483, Adjusted R-squared: 0.06722
## F-statistic: 1.829 on 2 and 21 DF, p-value: 0.1853
## non-parametric correlation with Spearman's
cor.test(data$violence, data$jvmean, method = "spearman")
##
## Spearman's rank correlation rho
##
## data: data$violence and data$jvmean
## S = 2304, p-value = 0.9951
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.00173913
cor.test(data$violence, data$jv0, method = "spearman")
## Warning in cor.test.default(data$violence, data$jv0, method = "spearman"): Kann
## exakten p-Wert bei Bindungen nicht berechnen
##
## Spearman's rank correlation rho
##
## data: data$violence and data$jv0
## S = 2422.2, p-value = 0.8053
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.05312438
## lets try to remove outliers
grubbs.test(data$jvmean)
##
## Grubbs test for one outlier
##
## data: data$jvmean
## G = 3.09211, U = 0.56622, p-value = 0.005598
## alternative hypothesis: highest value 6.01 is an outlier
grubbs.test(data$violence)
##
## Grubbs test for one outlier
##
## data: data$violence
## G = 1.86208, U = 0.84269, p-value = 0.66
## alternative hypothesis: highest value 90.4 is an outlier
data <- data[-15, ]
## with outlier excluded, lets try correlation again
cor.test(data$violence, data$jvmean, method = "spearman")
##
## Spearman's rank correlation rho
##
## data: data$violence and data$jvmean
## S = 2304, p-value = 0.5274
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.1383399
cor.test(data$violence, data$jv0, method = "spearman")
## Warning in cor.test.default(data$violence, data$jv0, method = "spearman"): Kann
## exakten p-Wert bei Bindungen nicht berechnen
##
## Spearman's rank correlation rho
##
## data: data$violence and data$jv0
## S = 2422.7, p-value = 0.3677
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## -0.1969812
## pvalue lower but still not significant
You can also embed plots, for example: