I have a very simple question. How would one fit a square root model to a dataset in Julia. I'm currently using the GLM
package, which works very well with linear data. I need to plot a phase velocity as a function of string tension, and it seems like @formula(v ~ sqrt(T))
does not work in
import GLM, DataFrames # No global namespace imports
df = DataFrames.DataFrame(
v = [1, 1.5, 1.75],
T = [1, 2, 3]
)
fit = GLM.glm(GLM.@formula(v ~ T^(1/2)), vs)
Is GLM
at all viable here, or do I need to resort to another package such as LsqFit
?
You can use sqrt
in your model formula. Just do it e.g. like this:
GLM.lm(GLM.@formula(v ~ sqrt(T)), df)
if you want to fit a linear model use lm
function and a second argument should be a data frame, which is df
in your case.