cc <- read.csv("http://blog.lib.umn.edu/wage0005/echinacea/Data%20for%20Analysis%20--%20cswitzer%20--%2031%20July%202011.csv")
str(cc) #structure
cc$compatible #gives values for this column
table(cc$compatible) #tells how many of each observation is in each
levels(cc$finalNotes) #tells the different text values in the column
summary(cc$distBetween) #gives a table of simple statistics for this column
hist(cc$distBetween, breaks = seq(0,60, by = 5)) #histogram for the column, with bin widths between 0 and 60, with breaks every 5
hist(cc$distBetween, breaks = seq(0,60, by = 2)) #histogram for the column, with bin widths between 0 and 60, with breaks every 2
cs <- subset (cc, compatible !=66) #subset of the column, gets rid of the value 66
plot(cs$neighborNumber, cs$compatible) #x,y plot of the subset created above
e1 <- subset (cs, site == "eelr1") #subset
e2 <- subset (cs, site == ("eelr2") #subset
ness <- subset (cs, site == "ness") #subset
spe <- subset (cs, site == "sppEast") #subset
spw <- subset (cs, site == "sppWest") #subset
nwlf <- subset (cs, site == "nwlf") #subset
str(e2)
table(e2$compatible)
# plots of neighborNumber and compatibility at each site
plot(e2$neighborNumber, e2$compatible) #not expected
plot(e1$neighborNumber, e1$compatible) #not expected
plot(ness$neighborNumber, ness$compatible) #not expected
plot(spe$neighborNumber, spe$compatible) #close to expected
plot(spw$neighborNumber, spw$compatible) #this data could be throwing off my analysis
table(spw$compatible) # not one compatible plant was found here... Weird.
plot(nwlf$neighborNumber, nwlf$compatible) #this plot looks like I was expecting
#plots of distBetween and compatibility (at each site)
plot(e2$distBetween, e2$compatible) #not expected
plot(e1$distBetween, e1$compatible) #not expected
plot(ness$distBetween, ness$compatible) #not expected
plot(spe$distBetween, spe$compatible) #not expected
plot(spw$distBetween, spw$compatible) #this data could be throwing off my analysis -- no compatible plants
table(spw$compatible) # not one compatible plant was found here... Weird.
plot(nwlf$distBetween, nwlf$compatible) #this plot looks like I was expecting
# time for some deeper statistics
#analysis for distbetween on eelr2 by itself; I don't think this is a valid test (due to small sample size)
m1 <- glm(compatible ~ distBetween, data = e2, family = binomial) #I don't know what the warining means
m0 <- glm(compatible ~ 1, data = e2, family = binomial)
anova(m0, m1, test= "Chi")
summary(m1)
plot(compatible ~ distBetween, data = e2) # plot(y ~ x)
predict(m1, type= "response", se.fit = TRUE)
newde2 <- data.frame(distBetween = 0:52)
pe2 <- predict(m1, newde2, type= "response", se.fit = TRUE)
newde2$fit <- p1$fit
newde2$se <- p1$se.fit
newde2
plot(compatible ~ distBetween, data = e2) # plot(y ~ x)
#points(25, .5, pch = "X")
points(0:52, newde2$fit, type = "l") # plot(y ~ x) #plot of line
points(0:52, newde2$fit + newd$se, type = "l", lty = 2) # plot(y ~ x); dotted upper std err line™
points(0:52, newde2$fit - newd$se, type = "l", lty = 2) # plot(y ~ x); dottedlower std err line
#analysis for distbetween on nwlf by itself -- Wow this is really messed up...I don't know why the line looks the way it does (also a small sample size).
h1 <- glm(compatible ~ distBetween, data = nwlf, family = binomial) #I don't know what the warining means
h0 <- glm(compatible ~ 1, data = nwlf, family = binomial)
anova(h0, h1, test= "Chi")
summary(h1)
plot(compatible ~ distBetween, data = nwlf) # plot(y ~ x)
predict(h1, type= "response", se.fit = TRUE)
newdNwlf <- data.frame(distBetween = 0:52)
pnwlf <- predict(m1, newdNwlf, type= "response", se.fit = TRUE)
newdNwlf$fit <- pnwlf$fit
newdNwlf$se <- pnwlf$se.fit
newdNwlf
plot(compatible ~ distBetween, data = Nwlf) # plot(y ~ x)
#points(25, .5, pch = "X")
points(0:52, newdNwlf$fit, type = "l") # plot(y ~ x) #plot of line
points(0:52, newdNwlf$fit + newd$se, type = "l", lty = 2) # plot(y ~ x); dotted upper std err line™
points(0:52, newdNwlf$fit - newd$se, type = "l", lty = 2) # plot(y ~ x); dottedlower std err line
#analysis for distbetween on full dataset
m1 <- glm(compatible ~ distBetween, data = cs, family = binomial) #
m0 <- glm(compatible ~ 1, data = cs, family = binomial)
anova(m0, m1, test= "Chi") #P = 0.008687, so this is a significant relationship
summary(m1)
plot(compatible ~ distBetween, data = cs) # plot(y ~ x)
predict(m1, type= "response", se.fit = TRUE)
newd <- data.frame(distBetween = 0:52)
p1 <- predict(m1, newd, type= "response", se.fit = TRUE)
newd$fit <- p1$fit
newd$se <- p1$se.fit
newd
plot(compatible ~ distBetween, data = cs) # plot(y ~ x)
#points(25, .5, pch = "X")
points(0:52, newd$fit, type = "l") # plot(y ~ x) #plot of line
points(0:52, newd$fit + newd$se, type = "l", lty = 2) # plot(y ~ x); dotted upper std err line™
points(0:52, newd$fit - newd$se, type = "l", lty = 2) # plot(y ~ x); dottedlower std err line
#analysis for full dataset, using neighborNumber
m1 <- glm(compatible ~ neighborNumber, data = cs, family = binomial)
m0 <- glm(compatible ~ 1, data = cs, family = binomial)
anova(m0, m1, test= "Chi") #P>0.05, so I can't conclude a significant relationship.
summary(m1)
plot(compatible ~ neighborNumber, data = cs) # plot(y ~ x)
predict(m1, type= "response", se.fit = TRUE)
newd <- data.frame(neighborNumber = 0:52)
p1 <- predict(m1, newd, type= "response", se.fit = TRUE)
newd$fit <- p1$fit
newd$se <- p1$se.fit
newd
plot(compatible ~ neighborNumber, data = cs) # plot(y ~ x)
#points(25, .5, pch = "X")
points(0:52, newd$fit, type = "l") # plot(y ~ x) #plot of line
points(0:52, newd$fit + newd$se, type = "l", lty = 2) # plot(y ~ x); dotted upper std err line™
points(0:52, newd$fit - newd$se, type = "l", lty = 2) # plot(y ~ x); dottedlower std err line
#this analysis also gives me the opposite of what I expected, even though I don't think there is a significant relationship