I am trying to model some data that follows a sigmoid curve relationship. In my field of work (psychophysics), a Weibull function is usually used to model such relationships, rather than probit.
I am trying to create a model using R and am struggling with syntax. I know that I need to use the vglm()
function from the VGAM
package, but I am unable to get a sensible model out. Here's my data:
# Data frame example data
dframe1 <- structure(list(independent_variable = c(0.3, 0.24, 0.23, 0.16,
0.14, 0.05, 0.01, -0.1, -0.2), dependent_variable = c(1, 1,
1, 0.95, 0.93, 0.65, 0.55, 0.5, 0.5)), .Names = c("independent_variable",
"dependent_variable"), class = "data.frame", row.names = c(NA,
-9L))
Here is a plot of the data in dframe1:
library(ggplot2)
# Plot my original data
ggplot(dframe1, aes(independent_variable, dependent_variable)) + geom_point()
This should be able to be modelled by a Weibull function, since the data fit a sigmoid curve relationship. Here is my attempt to model the data and generate a representative plot:
library(VGAM)
# Generate model
my_model <- vglm(formula = dependent_variable ~ independent_variable, family = weibull, data = dframe1)
# Create a new dataframe based on the model, so that it can be plotted
model_dframe <- data.frame(dframe1$independent_variable, fitted(my_model))
# Plot my model fitted data
ggplot(model_dframe, aes(dframe1.independent_variable, fitted.my_model.)) + geom_point()
As you can see, this doesn't represent my original data at all. I'm either generating my model incorrectly, or I'm generating my plot of the model incorrectly. What am I doing wrong?
Note: I have edited this question to make it more understandable; previously I had been using the wrong function entirely (weibreg()
). Hence, some of the comments below may not make sense.
.....
weibreg()
, but it seems like this was a red herring. I am very sorry.weibreg()
apparently only handles Weibull regression for survival models (which are commonly modeled with the Weibull) - but psychophysics seem to be unique in that they model non-survival data with a Weibull link function where everyone else would use a logit or probit. However, it looks like thevglm()
function in theVGAM
package may work: rss.acs.unt.edu/Rdoc/library/VGAM/html/weibull.html If you could add the output ofdput(dframe)
to your post, I will try to help more. – Librarianshipp
value comes from multiple observations, so I suggest you put them all in the data frame. Then I would fit the model usingmodel <- vglm(p~size,family=weibull,data=dframe)
(you will need to tellvglm()
what is the dependent and what is the independent variable) and examine the result withsummary(model)
. Your warning message means that the ML estimate yields an invalid shape parameter; it may disappear with more data. But I certainly won't say that I understandvglm
deeply; perhaps someone else can help? – Librarianship