Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. df <- data.frame(hour=c(0.50,0.75,1.00,1.25,1.50,1.75,1.75,2.00,2.25,2.50,2.75,3.00,3.25,3.50,4.00,4.25,4.50,4.75,5.00,5.50), pass=c(0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,1,1,1,1))
  2.  
  3. df
  4.  
  5. df$pass <- as.factor(df$pass)
  6. my_fit <- glm(df$pass ~ df$hour, data=df, na.action=na.exclude, family="binomial")
  7. summary(my_fit)
  8.  
  9. my_table <- summary(my_fit)
  10. my_table$coefficients[,1] <- invlogit(coef(my_fit))
  11. my_table
  12.  
  13. plot(df$hour, df$pass, xlab="x", ylab="logit values")
  14.  
  15. LinearPredictions <- predict(my_fit); LinearPredictions
  16.  
  17. EstimatedProbability.hat <- exp(LinearPredictions)/(1 + exp(LinearPredictions))
  18. EstimatedProbability.hat
  19.  
  20. EstimatedProbability <- c(0.25, 0.50, 0.75) # Estimated probabilities for which their x levels are wanted to be found
  21.  
  22. HoursStudied <- (log(EstimatedProbability/(1- EstimatedProbability)) - my_fit$coefficients[1])/ my_fit$coefficients[2]
  23. HoursStudied.summary <- data.frame(EstimatedProbability, HoursStudied)
  24. HoursStudied.summary
  25. EstimatedProbability HoursStudied
  26. #1 0.25 1.979936
  27. #2 0.50 2.710083
  28. #3 0.75 3.440230
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement