# \#glm

**URL:** https://discourse.julialang.org/tag/glm/351.md?page=1

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 2

---

## [Usage of lm with Unitful](https://discourse.julialang.org/t/usage-of-lm-with-unitful/87394)

<div class="topic-metadata">

**Author:** [@wheeheee](https://discourse.julialang.org/u/wheeheee)\
**Replies:** 0\
**Last updated:** [September 17, 2022, 6:25am UTC](https://discourse.julialang.org/t/usage-of-lm-with-unitful/87394 "2022-09-17T06:25:16Z")

</div>

I tried to use lm from GLM.jl with units from Unitful, but then received this error below. Is there some way to make this work? Or should I stick to stripping the units first before using lm? julia\> test\_df = DataFr…

---

## [Difference between allowrankdeficient and dropcollinear in lm function](https://discourse.julialang.org/t/difference-between-allowrankdeficient-and-dropcollinear-in-lm-function/86047)

<div class="topic-metadata">

**Author:** [@valperez](https://discourse.julialang.org/u/valperez)\
**Replies:** 2\
**Last updated:** [August 21, 2022, 6:44pm UTC](https://discourse.julialang.org/t/difference-between-allowrankdeficient-and-dropcollinear-in-lm-function/86047 "2022-08-21T18:44:04Z")

</div>

Hi there! I have a question regarding the documentation of the GLM package. I want to use the function lm(formula, data, allowrankdeficient=false; \[wts::AbstractVector\], dropcollinear::Bool=true) but I have a doubt…

---

## [ForwardDiff Dual Type problem with GLM](https://discourse.julialang.org/t/forwarddiff-dual-type-problem-with-glm/85045)

<div class="topic-metadata">

**Author:** [@YangkeunYun](https://discourse.julialang.org/u/YangkeunYun)\
**Replies:** 2\
**Last updated:** [July 31, 2022, 2:50pm UTC](https://discourse.julialang.org/t/forwarddiff-dual-type-problem-with-glm/85045 "2022-07-31T14:50:57Z")

</div>

Hi, I am working on ForwardDiff package to implement some optimizations. The core problem comes from Dual type (made by autodiff of ForwardDiff) and GLM package. I’ve seen other posts related to the issues with FowardD…

---

## [Iterate fitting linear model and extract coefficients over grouped DataFrame](https://discourse.julialang.org/t/iterate-fitting-linear-model-and-extract-coefficients-over-grouped-dataframe/84814)

<div class="topic-metadata">

**Author:** [@guysutton](https://discourse.julialang.org/u/guysutton)\
**Replies:** 4\
**Last updated:** [July 27, 2022, 10:45am UTC](https://discourse.julialang.org/t/iterate-fitting-linear-model-and-extract-coefficients-over-grouped-dataframe/84814 "2022-07-27T10:45:44Z")

</div>

I am trying to iteratively fit many models (e.g. a linear model \[GLM.jl\] or mixed model \[MixedModels.jl\]) to a DataFrame, whereby a new model is fit to each level of a grouping column. For example: if I wanted to fit one…

---

## [GLM.jl LogisticRegression errors: matrix is not positive definite; Cholesky factorization failed](https://discourse.julialang.org/t/glm-jl-logisticregression-errors-matrix-is-not-positive-definite-cholesky-factorization-failed/28981)

<div class="topic-metadata">

**Author:** [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Replies:** 14\
**Last updated:** [June 9, 2022, 10:04pm UTC](https://discourse.julialang.org/t/glm-jl-logisticregression-errors-matrix-is-not-positive-definite-cholesky-factorization-failed/28981 "2022-06-09T22:04:16Z")

</div>

The following errors: using DataFrames, GLM df = DataFrame(x1=\[1,2,3,4\], x2=\[1,2,3,4\], y=\[1,1,0,0\]) mdl = glm(@formula(y~x1+x2), df, Binomial(), LogitLink()) predict(mdl, df\[:, \[:x1, :x2\]\]) ERROR: LoadError: PosDef…

---

## [Does GLM return an estimate for the error term (residual standard deviation)?](https://discourse.julialang.org/t/does-glm-return-an-estimate-for-the-error-term-residual-standard-deviation/79614)

<div class="topic-metadata">

**Author:** [@charperflow](https://discourse.julialang.org/u/charperflow)\
**Replies:** 2\
**Last updated:** [April 18, 2022, 1:48pm UTC](https://discourse.julialang.org/t/does-glm-return-an-estimate-for-the-error-term-residual-standard-deviation/79614 "2022-04-18T13:48:57Z")

</div>

I was under the impression that if I called lm(@formula(y~x),data) from the GLM.jl package was fitting a simple linear regression of the form: y=a+bx\_i+\\epsilon\_i The results from the regression being: \\hat{y}=\\hat{a}…

---

## [Implementing r's stan\_glm() in Julia](https://discourse.julialang.org/t/implementing-rs-stan-glm-in-julia/78916)

<div class="topic-metadata">

**Author:** [@charperflow](https://discourse.julialang.org/u/charperflow)\
**Replies:** 5\
**Last updated:** [April 3, 2022, 7:56pm UTC](https://discourse.julialang.org/t/implementing-rs-stan-glm-in-julia/78916 "2022-04-03T19:56:55Z")

</div>

I am working through “Regression and Other Stories” for a class. All of the examples are done in R and I have been trying to recreate them in Julia for practice. For the most part it has been no problem, however, I am h…

---

## [DataFrame column names into GLM as variable names](https://discourse.julialang.org/t/dataframe-column-names-into-glm-as-variable-names/78422)

<div class="topic-metadata">

**Author:** [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Replies:** 2\
**Last updated:** [March 24, 2022, 10:43pm UTC](https://discourse.julialang.org/t/dataframe-column-names-into-glm-as-variable-names/78422 "2022-03-24T22:43:38Z")

</div>

I would like to use GLM to estimate 500 regressions like beta\[1\] = coef(lm(@formula(AAPL ~ SP500), Stocks))\[2\] beta\[2\] = coef(lm(@formula(AMGN ~ SP500), Stocks))\[2\] … beta\[i\] = coef(lm(@formula(col\_i ~ SP500), Stocks…

---

## [GLM - Questions](https://discourse.julialang.org/t/glm-questions/78191)

<div class="topic-metadata">

**Author:** [@DaKlingons](https://discourse.julialang.org/u/DaKlingons)\
**Replies:** 5\
**Last updated:** [March 22, 2022, 1:31am UTC](https://discourse.julialang.org/t/glm-questions/78191 "2022-03-22T01:31:42Z")

</div>

Hi All. I have 2 questions about implementing GLM.jl Weighting the Dependent Variable - I’m looking at using the Poisson distribution, whereby the dependent variable, is weighted by a Unit of Exposure (DaysActive/365…

---

## [GLM - inconsistency with R on ISLR dataset?](https://discourse.julialang.org/t/glm-inconsistency-with-r-on-islr-dataset/75427)

<div class="topic-metadata">

**Author:** [@compleat](https://discourse.julialang.org/u/compleat)\
**Replies:** 2\
**Last updated:** [January 30, 2022, 5:31pm UTC](https://discourse.julialang.org/t/glm-inconsistency-with-r-on-islr-dataset/75427 "2022-01-30T17:31:11Z")

</div>

I am teaching a class using the (well-known) book Intro to Statistical Learning in R (ISLR). For the Lab example in Chapter 3, there is an example using polynomial regression in GLM. According to documentation, the wa…

---

## [How do I fit generalised linear multilevel models including offsets?](https://discourse.julialang.org/t/how-do-i-fit-generalised-linear-multilevel-models-including-offsets/74286)

<div class="topic-metadata">

**Author:** [@timbp](https://discourse.julialang.org/u/timbp)\
**Replies:** 9\
**Last updated:** [January 10, 2022, 6:00am UTC](https://discourse.julialang.org/t/how-do-i-fit-generalised-linear-multilevel-models-including-offsets/74286 "2022-01-10T06:00:16Z")

</div>

I first heard of Julia a couple of years ago. It was presented as an alternative to R, SAS, and Stata. I had a look and I really liked it.The syntax just made sense. I could see where I might need to go to other languag…

---

## [Predict fails for simple case of GLM?](https://discourse.julialang.org/t/predict-fails-for-simple-case-of-glm/74102)

<div class="topic-metadata">

**Author:** [@compleat](https://discourse.julialang.org/u/compleat)\
**Replies:** 6\
**Last updated:** [January 5, 2022, 8:09pm UTC](https://discourse.julialang.org/t/predict-fails-for-simple-case-of-glm/74102 "2022-01-05T20:09:52Z")

</div>

I am trying a simple example using the ISLR dataset ols = lm(@formula(sales ~ TV + radio + newspaper), adsData) this works OK: \`\`StatsModels.TableRegressionModel{LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePred…

---

## [Adding logarithmic or polynomial regression to series](https://discourse.julialang.org/t/adding-logarithmic-or-polynomial-regression-to-series/73170)

<div class="topic-metadata">

**Author:** [@YummyPampers2](https://discourse.julialang.org/u/YummyPampers2)\
**Replies:** 11\
**Last updated:** [December 20, 2021, 4:49pm UTC](https://discourse.julialang.org/t/adding-logarithmic-or-polynomial-regression-to-series/73170 "2021-12-20T16:49:42Z")

</div>

Good Day: I have been attempting to fit a logarithmic or polynomial trendline to the following series: I am currently using GLM.jl and plotting with StatsPlots.jl, but do not believe there are parameters I can adj…

---

## [Multicollinearity and GLM](https://discourse.julialang.org/t/multicollinearity-and-glm/71340)

<div class="topic-metadata">

**Author:** [@rikh](https://discourse.julialang.org/u/rikh)\
**Replies:** 5\
**Last updated:** [November 11, 2021, 9:29pm UTC](https://discourse.julialang.org/t/multicollinearity-and-glm/71340 "2021-11-11T21:29:44Z")

</div>

Below, I show some generated data for a linear regression. With these features (also known as variables, covariates or predictors) A, B, C, D and E, I aim to predict an outcome Y. Would the data shown below be considered…

---

## [The simplest linear fit with GLM](https://discourse.julialang.org/t/the-simplest-linear-fit-with-glm/71316)

<div class="topic-metadata">

**Author:** [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Replies:** 13\
**Last updated:** [November 11, 2021, 2:33pm UTC](https://discourse.julialang.org/t/the-simplest-linear-fit-with-glm/71316 "2021-11-11T14:33:01Z")

</div>

EDIT: In the spirit of TL;DR, here is what you need to make a simple linear fit: julia\> X=\[1,2,3\]; Y=\[2,4,7\]; data = (;X, Y) (X = \[1, 2, 3\], Y = \[2, 4, 7\]) julia\> lm(@formula(Y~X), data) StatsModels.TableRegressionMode…

---

## [Extract @formula / model formula from GLM object](https://discourse.julialang.org/t/extract-formula-model-formula-from-glm-object/66610)

<div class="topic-metadata">

**Author:** [@guysutton](https://discourse.julialang.org/u/guysutton)\
**Replies:** 2\
**Last updated:** [October 8, 2021, 3:28pm UTC](https://discourse.julialang.org/t/extract-formula-model-formula-from-glm-object/66610 "2021-10-08T15:28:56Z")

</div>

I am trying to extract the model formula from a fitted GLM object, with little success. In the dummy example below, I would like to get the following back, for example: Y ~ X \[i.e. the information stored inside @formula(…

---

## [How to model seasonal data using GLM.jl](https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629)

<div class="topic-metadata">

**Author:** [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Replies:** 2\
**Last updated:** [September 23, 2021, 12:13pm UTC](https://discourse.julialang.org/t/how-to-model-seasonal-data-using-glm-jl/46629 "2021-09-23T12:13:05Z")

</div>

I would like to model some data that exhibits strong hourly seasonality. Additionally the data depends on the ambient temperature and if it is a holiday or workday. @formula(y ~ 1 + T\_amb + T\_amb^2 + hour\_of\_day(t)) O…

---

## [Two questions about GLM](https://discourse.julialang.org/t/two-questions-about-glm/10376)

<div class="topic-metadata">

**Author:** [@mwsohn](https://discourse.julialang.org/u/mwsohn)\
**Replies:** 4\
**Last updated:** [September 7, 2021, 5:55am UTC](https://discourse.julialang.org/t/two-questions-about-glm/10376 "2021-09-07T05:55:59Z")

</div>

I have noticed that I could not use a CategoricalArray as the dependent variable for a logistic regression. When I convert the binary dependent variable into a Float64, then I can estimate the model without any problem. …

---

## [Help fitting linear probability model with GLM.jl](https://discourse.julialang.org/t/help-fitting-linear-probability-model-with-glm-jl/67004)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 4\
**Last updated:** [August 26, 2021, 7:25am UTC](https://discourse.julialang.org/t/help-fitting-linear-probability-model-with-glm-jl/67004 "2021-08-26T07:25:57Z")

</div>

I’m looking to fit a linear probability model of the form: y\_i = \\alpha X\_i + PT\_i \\beta + \\phi\_j + \\lambda\_r + \\epsilon\_i Where: y\_i is 1 if worker is independent contractor on main job, else 0 X\_i is a vector of pe…

---

## [Error when using fit(LinearModel,...) through GLM](https://discourse.julialang.org/t/error-when-using-fit-linearmodel-through-glm/5781)

<div class="topic-metadata">

**Author:** [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Replies:** 1\
**Last updated:** [August 19, 2021, 6:14pm UTC](https://discourse.julialang.org/t/error-when-using-fit-linearmodel-through-glm/5781 "2021-08-19T18:14:59Z")

</div>

I want to perform a simple linear regression using this code: fit(LinearModel, @formula(Y ~ t + t2 + t3), regdata) I get the following error message: MethodError: no method matching getindex(::DataFrames.DataFrame, ::…

---

## [A subtle bug?](https://discourse.julialang.org/t/a-subtle-bug/61725)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 21\
**Last updated:** [May 25, 2021, 1:45pm UTC](https://discourse.julialang.org/t/a-subtle-bug/61725 "2021-05-25T13:45:59Z")

</div>

I got a Float64 number from the p-value of a GLM model. I could NOT show the fitted model with the following error: ERROR: p-values must be in \[0; 1\] Stacktrace: \[1\] error(::String) at ./error.jl:33 \[2\] StatsBase.PVa…

---

## [Weighted linear regression with confidence interval fitted to error bars](https://discourse.julialang.org/t/weighted-linear-regression-with-confidence-interval-fitted-to-error-bars/60743)

<div class="topic-metadata">

**Author:** [@Okarin99](https://discourse.julialang.org/u/Okarin99)\
**Replies:** 6\
**Last updated:** [May 9, 2021, 11:01am UTC](https://discourse.julialang.org/t/weighted-linear-regression-with-confidence-interval-fitted-to-error-bars/60743 "2021-05-09T11:01:23Z")

</div>

Hi, I’m pretty new to Data Science. I have some Data with measurement errors and I want to fit a linear model. using DataFrames using GLM using StatsPlots df = DataFrame(x = \[0.0, 0.0669873, 0.25, 0.5, 0.75, 0.933013…

---

## [Can someone replicate this GLM problem with linear regression on your computer?](https://discourse.julialang.org/t/can-someone-replicate-this-glm-problem-with-linear-regression-on-your-computer/60098)

<div class="topic-metadata">

**Author:** [@Chen](https://discourse.julialang.org/u/Chen)\
**Replies:** 13\
**Last updated:** [April 27, 2021, 1:31pm UTC](https://discourse.julialang.org/t/can-someone-replicate-this-glm-problem-with-linear-regression-on-your-computer/60098 "2021-04-27T13:31:59Z")

</div>

The CSV file is here: https://github.com/JuliaStats/GLM.jl/files/6384056/Car-Training.csv The GLM issue that I reported is here: https://github.com/JuliaStats/GLM.jl/issues/426 The codes are very simple: using GLM usi…

---

## [OLS with collinearity and weights using GLM.jl](https://discourse.julialang.org/t/ols-with-collinearity-and-weights-using-glm-jl/59787)

<div class="topic-metadata">

**Author:** [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Replies:** 3\
**Last updated:** [April 22, 2021, 11:49am UTC](https://discourse.julialang.org/t/ols-with-collinearity-and-weights-using-glm-jl/59787 "2021-04-22T11:49:26Z")

</div>

I am having a problem fitting an OLS model with weights and collinearity using GLM.jl. Here is a simple example y = rand(10) x = rand(10, 2) x = hcat(x,x) lm(x,y) # correctly removes last two columns lm(x, y, wts = one…

---

## [How do I force GLM to pass through a certain y intercept?](https://discourse.julialang.org/t/how-do-i-force-glm-to-pass-through-a-certain-y-intercept/59500)

<div class="topic-metadata">

**Author:** [@cocoa1231](https://discourse.julialang.org/u/cocoa1231)\
**Replies:** 3\
**Last updated:** [April 19, 2021, 3:07pm UTC](https://discourse.julialang.org/t/how-do-i-force-glm-to-pass-through-a-certain-y-intercept/59500 "2021-04-19T15:07:16Z")

</div>

Hello all! So I am using GLM to fit a graph of resistance vs. temperature, and I need the regression line to have an intercept of 100 Ohms at 0 degrees Centigrade. My code is - xdata = temp\_calib\_data\[:Pt100\]\[:, 1\] |\> …

---

## [Domain error when running user-defined function, but not when code is run outside function](https://discourse.julialang.org/t/domain-error-when-running-user-defined-function-but-not-when-code-is-run-outside-function/57771)

<div class="topic-metadata">

**Author:** [@guysutton](https://discourse.julialang.org/u/guysutton)\
**Replies:** 5\
**Last updated:** [March 23, 2021, 3:47pm UTC](https://discourse.julialang.org/t/domain-error-when-running-user-defined-function-but-not-when-code-is-run-outside-function/57771 "2021-03-23T15:47:05Z")

</div>

I am trying to write a function that will calculate deviance residuals for a general linear model (specified using GLM.jl). The function extracts predictions from the fitted model (pred), a vector containing the response…

---

## [Help with GLM logistic regression](https://discourse.julialang.org/t/help-with-glm-logistic-regression/56899)

<div class="topic-metadata">

**Author:** [@jonjilla](https://discourse.julialang.org/u/jonjilla)\
**Replies:** 4\
**Last updated:** [March 10, 2021, 7:01pm UTC](https://discourse.julialang.org/t/help-with-glm-logistic-regression/56899 "2021-03-10T19:01:21Z")

</div>

Can someone help me with using GLM for logistic regression. I’m testing this out on the iris dataset. using RDatasets iris = dataset("datasets","iris") I’ve worked with this before and know that the PetalLength is a …

---

## [Running counterfactuals on a regression with interactions](https://discourse.julialang.org/t/running-counterfactuals-on-a-regression-with-interactions/56711)

<div class="topic-metadata">

**Author:** [@samerb](https://discourse.julialang.org/u/samerb)\
**Replies:** 4\
**Last updated:** [March 8, 2021, 7:38am UTC](https://discourse.julialang.org/t/running-counterfactuals-on-a-regression-with-interactions/56711 "2021-03-08T07:38:21Z")

</div>

Let’s say I have a data frame with columns c1,c2,…,cn and I run a regression of c1 on c2, c3, c4 and c2.\*c4: sm = GLM.lm( @formula(c1 ~ c2 + c3 +c4 +c2&c4), df) If I were in Python, I could then do formula = 'c1 ~ c2 …

---

## [Error in Regression but I don't think there is collinearity: "PosDefException: matrix is not positive definite; Cholesky factorization failed."](https://discourse.julialang.org/t/error-in-regression-but-i-dont-think-there-is-collinearity-posdefexception-matrix-is-not-positive-definite-cholesky-factorization-failed/56689)

<div class="topic-metadata">

**Author:** [@samerb](https://discourse.julialang.org/u/samerb)\
**Replies:** 0\
**Last updated:** [March 7, 2021, 4:51pm UTC](https://discourse.julialang.org/t/error-in-regression-but-i-dont-think-there-is-collinearity-posdefexception-matrix-is-not-positive-definite-cholesky-factorization-failed/56689 "2021-03-07T16:51:55Z")

</div>

“PosDefException: matrix is not positive definite; Cholesky factorization failed.” I am getting the above error when I try to do certain regressions such as the one below involving interaction terms involving some binar…

---

## [Regression using Categorical variables](https://discourse.julialang.org/t/regression-using-categorical-variables/7521)

<div class="topic-metadata">

**Author:** [@lukaebby](https://discourse.julialang.org/u/lukaebby)\
**Replies:** 16\
**Last updated:** [February 19, 2021, 10:23pm UTC](https://discourse.julialang.org/t/regression-using-categorical-variables/7521 "2021-02-19T22:23:45Z")

</div>

Can anyone tell me how to define categorical variables (with more than two levels) while performing regression in Julia…? Thanks say my data is my\_dataframe= DataFrame(class=\[3,1,3,2,1,2,1\],hist=\[34,36,38,40,42,44,46\]…

[Previous page](https://discourse.julialang.org/tag/glm/351.md?match_all_tags=true&tags%5B%5D=glm)

[Next page](https://discourse.julialang.org/tag/glm/351.md?match_all_tags=true&page=2&tags%5B%5D=glm)
