CS计算机代考程序代写 # Read in the data, create a data frame called “Crabs”

# Read in the data, create a data frame called “Crabs”

rm(list=ls()); set.seed(20210404);

filename <- "http://www.stat.ufl.edu/~aa/cat/data/Crabs.dat" Crabs <- read.table(filename, header=T) dim(Crabs); names(Crabs); summary(Crabs$width) mean(Crabs$width); sd(Crabs$width); hist(Crabs$width, freq=F, right=F); lines(density(Crabs$width)); # Here we consider a logistic regression with response # variable y = 1 if satellite(s), 0 if none plot(jitter(y,.2) ~ width, data=Crabs) fit <- glm(y ~ width, data=Crabs, family=binomial) range(Crabs$width) x <- seq(21.0, 33.5, .125) curve(predict(fit, data.frame(width=x), type="response"), add=T) fit.lo <- loess(y ~ width, data=Crabs) curve(predict(fit.lo, data.frame(width=x)), add=T, lty=2) # Fitted curves not so different, and where they differ only the # logistic curve makes sense (loess goes above 1.0) # Fit logistic regression of "presence of satellite" on width m1 <- glm(y ~ width, data=Crabs, family=binomial) summary(m1) confint(m1) # Median effect level alpha.hat <- as.numeric(coef(m1)["(Intercept)"]) beta.hat <- as.numeric(coef(m1)["width"]) alpha.hat; beta.hat; EL.50 <- -alpha.hat / beta.hat; EL.50; # Crab of width 24.84 cm has 50-50 chance of satellite(s)