6,537 questions
0
votes
1
answer
77
views
stat_regline_equation() doesn't match stat_smooth() line
I'm getting an odd problem where I've attempted to plot a scatter graph and fit a quadratic regression line to it. I used stat_smooth() to make the line, and stat_regline_equation() to print the ...
1
vote
0
answers
163
views
Plotting linear regression for geometric intuition
I am regressing Y~(X1, X2) such that this fit is perfect (R squared is 1), where the R squared for Y~X1 and Y~X2 are chosen somewhere in the interval $(0,1)$. I am trying to create the numerical ...
1
vote
0
answers
44
views
lm() and glm() equivalence for log-transformed response variable [migrated]
I can't seem to wrap my head around this:
What is the glm() equivalent for lm(log(y) ~ x1 + x2, data=data)?
Is it?
a. glm(y ~ x1 + x2, data=data, family=gausssian(link="log"))
b. glm(log(y) ...
0
votes
0
answers
59
views
How to make an interactive console version in Java for a simple linear regression model?
I’m trying to create a simple model in Java that predicts marks based on study hours (using a basic linear regression formula).
My goal is to make it interactive — where the user can enter the number ...
2
votes
0
answers
88
views
Quantify sum of squared differences in a robust multilinear regression in R
I would like to obtain estimates of the variance explained by each predictor in multiple regression using robust linear regression (for instance with the R function lmrob from robustbase R package or ...
-3
votes
1
answer
39
views
is mmec function of sommer package deprecated in latest version?
I just want to ask whether the function mmec is deprecated in the latest version? because when I am trying to use it, its displaying (could not find function "mmec") message. It is ...
0
votes
0
answers
66
views
Why is my plot of the cost function like this and not like a bowl?
My code:
def calc_cost_function(w, b, data):
m = len(data)
cost = 0
for i in range(m):
x = data.iloc[i].X
y = data.iloc[i].Y
cost += ((x * w + b) - y)**2
return ...
0
votes
1
answer
46
views
How to perform pairwise weighted least squares regression on multiple columns?
I'm working with DolphinDB and trying to compute weighted least squares (WLS) regression between multiple pairs of columns in a table. The mslr function (moving least squares regression) works ...
1
vote
1
answer
74
views
Memory management issues for a linear regression program in C
I am planning to make a Linear Regression model using C. It takes a set of m points as input from stdin using scanf. The points are defined as a struct:
typedef struct{
double x;
double y;
} ...
2
votes
1
answer
95
views
Why is there a major difference in R-Squared between my models created with the same data? [closed]
I created two models using the lm() function in R. The first model, I created the design matrix for my prediction variable and then fed that into the lm() function.
copy <- data.frame(mtcars)
...
3
votes
0
answers
76
views
Orthogonal Distance Regression (ODR) convergence on valid data
I have some real data points, and I'm trying to use the ODR to fit linear regression and also output the uncertainty error of the slope.
import numpy as np
from scipy.odr import ODR, Model, RealData
...
0
votes
1
answer
27
views
Why Does ols Fail with 'Dimension Mismatch' When Using sqlCol for Multiple Columns in DolphinDB?
In DolphinDB, I'm trying to perform multiple regression on multiple columns by using metaprogramming function sql, but I'm getting an error.
Here's my script:
sql(sqlColAlias(makeUnifiedCall(toArray, ...
2
votes
2
answers
66
views
Needing advice on linear regression and then replacing NA's with fitted values
I am quite new to the data analytics stuff and R/RStudio so I am in need of advice. I am doing a project and asked to do:
for every variable that has missing value to run a linear regression model ...
0
votes
1
answer
48
views
Gradient descent in linear regression causing parameter to be -infinity
I'm trying to implement a simple linear regression algo, and for that I've written two functions:
Cost function
Gradient descent
Cost function appears to work normally, as in it's not giving me ...
3
votes
1
answer
132
views
Plot the best fit linear regression with the slope set to a fixed value (m=1)
Currently using R 4.4.3 on Windows 11. I'm plotting the following data set with ggplot2 and performing a linear regression with geom_smooth:
df <- data.frame(A= c(1.313, 1.3118, 1.3132, 1.3122, 1....
6
votes
2
answers
138
views
Residual Analysis for simple linear regression model
I'm trying to conduct the residual analysis for simple linear regression. I need to prove that the residuals follow an approximate Normal Distribution.
The csv file I'm using has values for Percentage ...
0
votes
0
answers
30
views
Python's analog of xtregar
I'm new in Python. I would like to know wheter there is a package that performs the same thing as Stata's 'xtregar' ou R's 'panelAR'.
I would like to estimate the following regression
Y_{i,t}=\alpha+\...
6
votes
1
answer
78
views
Does the way you numerically encode data for a regression matter? [closed]
I'm looking to build out a multiple regression in Python and need to numerically encode my categorical data. I have fields such as gender (Male, Female, Prefer not to Say), education level (High ...
0
votes
0
answers
49
views
Add weighting function to an existing Pine Script
The pine-script below is a variant of a script published by henryph24 to plot the linear regression slope:
//This source code is subject to the terms of the Mozilla Public License 2.0 at https://...
2
votes
1
answer
294
views
Why does SequentialFeatureSelector return at most "n_features_in_ - 1" predictors?
I have a training dataset with six features and I am using SequentialFeatureSelector to find an "optimal" subset of the features for a linear regression model. The following code returns ...
0
votes
0
answers
26
views
Validity of forcing line through origin in multiple regression
I am trying to fit a multiple regression model to my data. I am testing the hypothesis that outcome Y is linearly related to independent variable X, while controlling for a linear relationship with ...
0
votes
0
answers
23
views
LinearRegression object has no attr coef_ (in pipeline)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
num_features, bin_features, cat_features = split_features(X)
preprocessor = ColumnTransformer([
('num', ...
3
votes
2
answers
103
views
How to generate a polynomial regression formula from a list of column names
It's in the title, however here is an example
# df is the sample data
df <- data.frame(a = c(1:10), b= c(10:20), c = c(20:30), d= c(30:40))
rq_cols <- c(a,b,c)
#the desired output is:
fn <- ...
0
votes
0
answers
41
views
How can I extract absolute beta coefficients for all levels of multiple categorical variables in statsmodels?
I’m performing linear regression in Python with statsmodels. I have two categorical predictors:
sample: a factor with 8 levels
distractor: a factor with 2 levels
My goal is to determine the “...
0
votes
0
answers
34
views
How to perform OLS regression in Matlab with constraints on coefficients?
I want to apply constrained ordinary least-squares regression similar to what is done with R here, but in Matlab. The documentation doesn't suggest how to accomplish this with the available routine ...
2
votes
0
answers
53
views
How can I prevent stepAIC in caret::train from removing main effects involved in interaction terms to maintain hierarchical regression principles?
I’m using caret::train in R with method = "glmStepAIC" to perform stepwise regression with repeated cross-validation (trControl = splitRule). My model includes interaction terms and I want ...
1
vote
1
answer
115
views
Added variable / partial regression plots for groups in an interaction?
I'm looking to make added variable / partial regression plots for a regression with an interaction, which we can do with car.
# packages
library(car)
# linear model with 2-way interaction
lm1 <- lm(...
0
votes
1
answer
155
views
Singular Matrix 'a' in solve
I am trying to use predict function in RStudio on some new data. However I keep getting an error, "Error in qr.solve(qr.R(qrX)[p1, p1]) : singular matrix 'a' in solve". Where is my mistake? ...
1
vote
1
answer
59
views
Error conducting regression (stepwise) AIC is -infinity for this model, so 'step' cannot proceed
This is my first consult, happy to share the community :) (You would notice I'm not a native english speaker and also I'm not very good using R, actually these are my firsts steps).
I'm trying to ...
0
votes
0
answers
26
views
Using PCA to "Penalize" Duplicates in a Dataset
I have a large proteomics dataset with thousands of proteins that I am regressing against an outcome to determine which proteins associate with the outcome. Some of the proteins appear multiple times ...
0
votes
0
answers
20
views
Can Gradient Information Be Exposed in Vertical Federated Linear Regression Without Leaking Label Information?
In Vertical Federated Logistic Regression, suppose there are two parties, A and B, where Party B holds the label values. If Party A obtains the gradient information in plaintext, it can infer the ...
1
vote
1
answer
110
views
Finding projections of points to a (hyper)plane along all coordinate axes
I have a set of linear regression problems, whose dimensionalities vary from 2D (line fitted to a single independent variable), to 3D (plane fitted to two independent variables) to nD where hyperplane ...
1
vote
1
answer
75
views
What is the difference between setting the engine parameter in linear_reg() implicitly vs. explicitly?
I am doing a course on linear regression with R using the tidymodels package and the sample code for specifying the linear regression model is:
linear_model_specification <- linear_reg() %>%
...
0
votes
0
answers
23
views
Power analysis for multiple regression with binary moderator - Determining sample size
I want to conduct an a priori power analysis to determine the necessary sample size for a proposed project. I will estimate a regression between two continuous variables with a binary moderator (...
0
votes
0
answers
62
views
How to find optimal split of train and test to return the minimum RMSE for Boston housing data set without looping
I'm working to minimize the RMSE for the Boston housing data set. This is a very basic result:
library(Metrics)
df <- MASS::Boston
train <- df[1:400, ]
test <- df[401:506, ]
Boston_lm <- ...
0
votes
0
answers
29
views
The model does not predict the data several steps ahead
I'm trying to train a model to predict the close column 2 steps ahead. Prepared the dataset:
datetime
close
close_forward
close_shift_1
close_shift_2
close_shift_3
close_shift_4
close_shift_5
2024-10-...
2
votes
0
answers
50
views
What null hypothesis is rejected by the value of statsmodels RLM
I am using statsmodels to perform a robust linear regression on some data I have. I wanted to understand whether the slope of my regression is significantly different from 0. In scipy I due this by ...
2
votes
1
answer
118
views
Finding the deviation point from an initial linear trend with python
I am working with stress-strain curves which initially has a linear trend after which there the trend is variable from test to test. I am trying to find the point at which the data deviates from this ...
0
votes
1
answer
107
views
Why do I plot only one feature when visualizing predictions for a multi-feature regression model?
I am working on a regression task where my feature matrix consists of two features: a linear term and its square (quadratic feature). My model is predicting values correctly, but after numerous ...
0
votes
0
answers
35
views
Issues when minimizing cost function in a simple linear regression
I'm quite new to ML and I'm trying to do a linear regression with quite a simple dataset: text
I did two different regression, one by hand and the other one using sci kit learn, where in the latter I ...
0
votes
1
answer
40
views
Linear regression model barely optimizes the intercept b
I've programmed a linear regression model from scratch. I use the "Sum of squared residuals" as the loss function for gradient descent. For testing I use linear data (y=x)
When running the ...
1
vote
0
answers
59
views
Making a regression table to compare multiple models side by side in R but "length of NULL cannot be changed" error
I'm running a linear regression model and then a standard error mean model + trying to view their results together in a table
lm1 <- lm(foodsec_pct_male ~
log(agri_employment_share) +
...
5
votes
1
answer
100
views
Is this a mistake in R? To my understanding the output should be the same
Recently, I was comparing two statistics exercises and found out that different outputs for the same input in R is perhaps unintended behavior of R, right?
model1 <- lm(rent ~ area + bath, data = ...
0
votes
0
answers
36
views
How to apply OLS with constraints on coefficients and align the output scale with the target variable?
I am working on an OLS regression problem where:
The dependent variable (target) ranges from 1 to 6 (with steps of 1).
The independent variables range from 1 to 10 (with steps of 0.5).
I want to set ...
0
votes
0
answers
53
views
Regression table with model with re-specified standard errors
I am running models with plm with re-calculated standard errors. The challenge? I want to turn the models with the updated standards errors into a stargazer regression table.
Here is some sample data
...
0
votes
1
answer
96
views
Scatter plot showing data points with negative values when there are no negative values in the dataset
I have an issue with this linear regression model. The scatter plot shows data points well into the negative when no negative values are within the data set. I've checked the shapes and minimum values ...
0
votes
0
answers
18
views
How to operate with complex coefficients in patsy and is it possible?
I tried to construct dmatrix from the dataframe of dtype='complex', but I got the error:
numpy.core._exceptions._UFuncOutputCastingError: Cannot cast ufunc 'multiply' output from dtype('complex128') ...
0
votes
0
answers
29
views
Alternative to forecast sequential regressions
Seeking advice on how I could forecast the below better. Ultimately I am looking to build a 5-year rent growth forecast, but as part of the forecasting process, I will need other variables.
Currently, ...
0
votes
1
answer
142
views
How do I make a neural network class with fit and predict functions like with sklearn models, when my train and test data are different sizes?
I'm trying to make a neural network model that will answer a linear regression problem (I've already made a model using sklearn's LinearRegression and I'd like to compare the two). Ultimately I'd ...
0
votes
1
answer
78
views
R: add summation to regression equation
I am trying to write this formula in R where i = each value of the category (category can be 1 2 3 or 4)
This is my code attempt but R prints this error message:
Error in lm(category ~ (year * state *...