# How to pass a function in a variable inside a linear regression?

Hi, im trying to replicate this excercises in R, but in Julia and wanted to know if thereβs a way to do what they did in 2.2, that is, passing a linear model the next way

linearRegressor = lm(log(dependente variable ) ~ independent variables, dataset)

I had to create a new column in my dataset with

dataset.column = log.(dataset.column)

to solve the problem, but wanted to know if Julia have a way to do this.

Thank for any help.

Did you try it? It should work.

``````julia> lm(@formula(log(y) ~ x), df)
StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Array{Float64,1}},GLM.DensePredChol{Float64,LinearAlgebra.Cholesky{Float64,Array{Float64,2}}}},Array{Float64,2}}

:(log(y)) ~ 1 + x

Coefficients:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Estimate  Std. Error   t value  Pr(>|t|)  Lower 95%  Upper 95%
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
(Intercept)  0.37625     0.0381661  9.85821     <1e-15   0.30051    0.451989
x            0.0331787   0.0735028  0.451394    0.6527  -0.112685   0.179043
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
``````
2 Likes

Thanks, I had tried originally as

fm = @formula(log.(y) ~ x)

and that gave an error and didnβt tough was the β.β the cause it.