Skip to content

Instantly share code, notes, and snippets.

## model selection
# This is Max Kuhn's tutorial on caret: http://topepo.github.io/caret/training.html
library(mlbench)
data(Sonar)
str(Sonar[, 1:10])
library(caret)
set.seed(998)
# here is the data:
# http://www.ams.usda.gov/AMSv1.0/getfile?dDocName=STELPRDC5087258
# You'll need to remove the first two lines and save a .csv file
setwd("C:/Users/abc/Downloads")
markets <- read.csv("farmers-market.csv")
OR.markets <- markets %>%
filter(State=="Oregon")
require(ggplot2)
# http://ww2.coastal.edu/kingw/statistics/R-tutorials/independ.html
# Study 1A
# find numbers for chi square table
indy_affect <- round(.552*29)
inter_affect <- round(.29*31)
inter_cog <- round(.71*31)
pf(q=6.21, df1=1, df2=132, lower.tail=FALSE) # interaction self-construal and mood
pf(q=4, df1=1, df2=132, lower.tail=FALSE)
pf(q=2.33, df1=1, df2=132, lower.tail=FALSE)
# chi-squared test
chisq.test(tbl) # Yate's continuity correction is the default
chisq.test(tbl, correct=FALSE) # no Yate's continuity correction
fisher.test(tbl) # fisher's exact test for count data
chisq.test(tbl, simulate.p.value=T, B=999) # Markov chain
# find numbers for chi square table
indy_affect <- round(.552*29)
inter_affect <- round(.29*31)
inter_cog <- round(.71*31)
indy_cog <- round(.448*29)
# build table
tbl <- matrix(c(indy_affect,indy_cog,inter_affect,inter_cog),nrow=2)
colnames(tbl) <- c("Indie","Inter")
rownames(tbl) <- c("Affect","Cog")