linear-regression

Standardized regression coefficients with dummy variables in R vs. SPSS

谁说我不能喝 提交于 2020-06-17 02:03:07
问题 I came across a puzzling difference in standardized (beta) coefficients with linear regression model computed with R and SPSS using dummy coded variables. I have used the hsb2 data set and created a contrast (dummy coding), so that the third category is the reference. Here is the R code: # Read the data hsb2 <- read.table('https://stats.idre.ucla.edu/stat/data/hsb2.csv', header = TRUE, sep = ",") # Create a factor variable with respondents' race hsb2$race.f <- factor(hsb2$race, labels = c(

How to plot CCDF graph on a logarithmic scale?

為{幸葍}努か 提交于 2020-06-11 10:41:46
问题 I want to plot a CCDF graph for some of my simulated power-law tail data on a log-log axis, below is my R code of plotting a CCDF graph on a normal axis, I used the code on the link: (How to plot a CCDF gragh?) > load("fakedata500.Rda") > x<-fakedata500 > f<-ecdf(x) > f Empirical CDF Call: ecdf(x) x[1:500] = 0.50174, 0.50307, 0.50383, ..., 81.674, 140.63 > plot(f) Below is the ECDF graph: > plot(sort(x), 1-f(sort(x)), type="s", lwd=1) and this command gives me the CCDF graph: However, I would

How to instantiate a Scikit-Learn linear model with known coefficients without fitting it

笑着哭i 提交于 2020-05-22 03:51:15
问题 Background I am testing various saved models as part of an experiment, but one of the models comes from an algorithm I wrote, not from a sklearn model-fitting. However, my custom model is still a linear model so I want to instantiate a LinearModel instance and set the coef_ and intercept_ attributes to the values from my custom fitting algorithm so I can use it for predictions. What I tried so far: from sklearn.linear_model import LinearRegression my_intercepts = np.ones(2) my_coefficients =

How to instantiate a Scikit-Learn linear model with known coefficients without fitting it

梦想的初衷 提交于 2020-05-22 03:49:11
问题 Background I am testing various saved models as part of an experiment, but one of the models comes from an algorithm I wrote, not from a sklearn model-fitting. However, my custom model is still a linear model so I want to instantiate a LinearModel instance and set the coef_ and intercept_ attributes to the values from my custom fitting algorithm so I can use it for predictions. What I tried so far: from sklearn.linear_model import LinearRegression my_intercepts = np.ones(2) my_coefficients =

Simple logistic regression with Statsmodels: Adding an intercept and visualizing the logistic regression equation

假如想象 提交于 2020-05-16 05:54:09
问题 Using Statsmodels, I am trying to generate a simple logistic regression model to predict whether a person smokes or not (Smoke) based on their height (Hgt). I have a feeling that an intercept needs to be included into the logistic regression model but I am not sure how to implement one using the add_constant() function. Also, I am unsure why the error below is generated. This is the dataset, Pulse.CSV: https://drive.google.com/file/d/1FdUK9p4Dub4NXsc-zHrYI-AGEEBkX98V/view?usp=sharing The full

How to find the best degree of polynomials?

纵然是瞬间 提交于 2020-05-09 18:55:06
问题 I'm new to Machine Learning and currently got stuck with this. First I use linear regression to fit the training set but get very large RMSE. Then I tried using polynomial regression to reduce the bias. import numpy as np from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures from sklearn.metrics import mean_squared_error poly_features = PolynomialFeatures(degree=2, include_bias=False) X_poly = poly_features.fit_transform(X) poly_reg =

Linear Regression in Javascript

試著忘記壹切 提交于 2020-05-09 18:17:21
问题 I want to do Least Squares Fitting in Javascript in a web browser. Currently users enter data point information using HTML text inputs and then I grab that data with jQuery and graph it with Flot. After the user had entered in their data points I would like to present them with a "line of best fit". I imagine I would calculate the linear, polynomial, exponential and logarithmic equations and then choose the one with the highest R^2 value. I can't seem to find any libraries that will help me

How to run linear regression model for each industry-year excluding firm i observations in R?

白昼怎懂夜的黑 提交于 2020-04-30 06:57:07
问题 Here is the dput output of my dataset in R...... data1<-structure(list(Year = c(1998, 1999, 1999, 2000, 1996, 2001, 1998, 1999, 2002, 1998, 2005, 1998, 1999, 1998, 1997, 1998, 2000), `Firm name` = c("A", "A", "B", "B", "C", "C", "D", "D", "D", "E", "E", "F", "F", "G", "G", "H", "H"), Industry = c("AUTO", "AUTO", "AUTO", "AUTO", "AUTO", "AUTO", "AUTO", "AUTO", "AUTO", "Pharma", "Pharma", "Pharma", "Pharma", "Pharma", "Pharma", "Pharma", "Pharma"), X = c(1, 2, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16

How can i get the shapiro-wilk test

冷暖自知 提交于 2020-04-18 01:14:06
问题 I want to do the shapiro-wilk test for my regressions. Here is my code library(data.table) Regresiones_shapirotest_1<- data.table(tabla.Enero)[, .(Lm = lapply(.SD, function(x) resid(lm(tabla.Enero$PPNA ~ x)))), .SDcols = 15:93] I can get the test values only in the console Regresiones_shapirotest_1 [, lapply(Lm, shapiro.test)] [2] write.xlsx (Regresiones_shapirotest_1 , file = "shapirotest.xlsx", sheetName = "Hoja1", Col.names = TRUE, row.names = TRUE, append = FALSE) But when I try to export

How can i get the shapiro-wilk test

狂风中的少年 提交于 2020-04-18 01:11:32
问题 I want to do the shapiro-wilk test for my regressions. Here is my code library(data.table) Regresiones_shapirotest_1<- data.table(tabla.Enero)[, .(Lm = lapply(.SD, function(x) resid(lm(tabla.Enero$PPNA ~ x)))), .SDcols = 15:93] I can get the test values only in the console Regresiones_shapirotest_1 [, lapply(Lm, shapiro.test)] [2] write.xlsx (Regresiones_shapirotest_1 , file = "shapirotest.xlsx", sheetName = "Hoja1", Col.names = TRUE, row.names = TRUE, append = FALSE) But when I try to export