Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Second assignment
- #2.1
- #Target = blood.Systolic, Weight & height are variables.
- data <- as.data.frame(read.csv("Women.csv", sep = ";"))
- #fit=glm(formula = Blood.systolic~., data = data)
- logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
- # m = glm(y ~ 0 + x^2, family = gaussian, start = start, ...)
- xy=cbind(x[,-1],y)
- x=x[,-1]
- data=as.data.frame(xy)
- ret=lm(y~.^2, data=data)
- return(ret)
- }
- #Wrongly followed the vignette instruction at slide 7.
- #Did not understand that model generated false solutions as the results of our plots very reasonable.
- #Also the warning message did not seem too unreasonable.
- #When investigating the solution noticed that the first column of x should be extracted.
- library(grid)
- library(libcoin)
- library(mvtnorm)
- library(partykit)
- library(sandwich)
- model = mob(Blood.systolic~.|height+weight, data = data, fit = logit, control = mob_control(minsize = 5000))
- plot(model)
- sortedHeights = sort(data$height)
- sortedWeights = sort(data$weight)
- height = seq(sortedHeights[1],sortedHeights[length(sortedHeights)],length.out = 100)
- weight = seq(sortedWeights[1],sortedWeights[length(sortedWeights)],length.out = 100)
- test = expand.grid(height, weight)
- colnames(test) = c("height","weight")
- predictions = predict(model, newdata = test, type="response")
- #Edited after hand-in (COMPLETION)
- #Changed from type link to type response
- library(ggplot2)
- library(gridExtra)
- ggplot(test, aes(height,weight, fill = predictions)) + geom_raster()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement