regression

R: Isotonic regression Minimisation

时光总嘲笑我的痴心妄想 提交于 2019-12-11 12:05:51
问题 I want minimize the following equation: F=SUM{u 1:20}sum{w 1:10} Quw(ruw-yuw) with the following constraints: yuw >= yu,w+1 yuw >= yu-1,w y20,0 >= 100 y0,10 >= 0 I have a 20*10 ruw and 20*10 quw matrix, I now need to generate a yuw matrix which adheres to the constraints. I am coding in R and am familiar with the lpsolve and optimx packages, but don't know how to use them for this particular question. 回答1: Because Quw and ruw are both data, all constraints as well as the objective are linear

R— repeating linear regression in a large dataset

≯℡__Kan透↙ 提交于 2019-12-11 11:56:46
问题 I'm an R newbie working with an annual time series dataset (named "timeseries"). The set has one column for year and another 600 columns with the yearly values for different locations ("L1," "L2", etc), e.g. similar to the following: Year L1 L2 L3 L4 1963 0.63 0.23 1.33 1.41 1964 1.15 0.68 0.21 0.4 1965 1.08 1.06 1.14 0.83 1966 1.69 1.85 1.3 0.76 1967 0.77 0.62 0.44 0.96 I'd like to do a linear regression for each site and can use the following for a single site: timeL1<-lm(L1~Year, data

Categorical variables in R - which one does R pick as reference?

谁说胖子不能爱 提交于 2019-12-11 11:53:51
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 4 years ago . When R performs a regression using a categorical variable, it's effectively dummy coding. That is, one of levels is omitted as base or reference and the regression formula includes dummies for all the other levels. But which one is it, that R picks as reference and how I can influence this choice? Example data with four levels (from UCLA's IDRE): hsb2 <- read.csv("http://www

R: HAC by NeweyWest using dynlm

我与影子孤独终老i 提交于 2019-12-11 11:47:06
问题 This is what I would like to do: library("lmtest") library("dynlm") test$Date = as.Date(test$Date, format = "%d.%m.%Y") zooX = zoo(test[, -1], order.by = test$Date) f <- d(Euribor3) ~ d(Ois3) + d(CDS) + d(Vstoxx) + d(log(omo)) + d(L(Euribor3)) m1 <- dynlm(f, data = zooX, start = as.Date("2005-01-05"),end = as.Date("2005-01-24")) m2 <- dynlm(f, data = zooX, start = as.Date("2005-01-25"), end=as.Date("2005-02-14")) summary(m1) summary(m2) coeftest(m1, vcov=NeweyWest) coeftest(m2, vcov=NeweyWest

PyTorch does not converge when approximating square function with linear model

六月ゝ 毕业季﹏ 提交于 2019-12-11 09:58:36
问题 I'm trying to learn some PyTorch and am referencing this discussion here The author provides a minimum working piece of code that illustrates how you can use PyTorch to solve for an unknown linear function that has been polluted with random noise. This code runs fine for me. However, when I change the function such that I want t = X^2, the parameter does not seem to converge. import torch import torch.nn as nn import torch.optim as optim from torch.autograd import Variable # Let's make some

how to get the fstat out of fitlm MATLAB

江枫思渺然 提交于 2019-12-11 09:17:49
问题 I'm using lm = fitlm(X,y,'linear') it works nicely and outputs lm = Linear regression model: y ~ 1 + x1 + x2 + x3 Estimated Coefficients: Estimate SE tStat pValue (Intercept) 2.1338 0.27403 7.7869 1.6357e-13 x1 0.07202 0.01757 4.0991 5.5484e-05 x2 -0.35927 0.12078 -2.9746 0.0032094 x3 0.020363 0.0041479 4.9092 1.6168e-06 Number of observations: 264, Error degrees of freedom: 260 Root Mean Squared Error: 0.835 R-squared: 0.154, Adjusted R-Squared 0.144 F-statistic vs. constant model: 15.8, p

Equivalent of predict_proba for DecisionTreeRegressor

风格不统一 提交于 2019-12-11 08:29:45
问题 scikit-learn's DecisionTreeClassifier supports predicting probabilities of each class via the predict_proba() function. This is absent from DecisionTreeRegressor : AttributeError: 'DecisionTreeRegressor' object has no attribute 'predict_proba' My understanding is that the underlying mechanics are pretty similar between decision tree classifiers and regressors, with the main difference being that predictions from the regressors are calculated as means of potential leafs. So I'd expect it to be

Add formula terms programmatically

怎甘沉沦 提交于 2019-12-11 08:20:50
问题 I am running a simulation and need to test the performance of different sized formulas. Drawing from data frame with columns V1, V2, V3... Vk, I need to programmatically create formulas like fit <- ols(y ~ V1 + V2 + V3, data=dataframe) and so forth. How can I code the formula to be able to scale the length of the formula? 回答1: You can convert text to a formula: vars <- c(1, 2, 4) formula.text <- paste0("y ~ V", paste(vars, collapse=" + V")) formula.text # [1] "y ~ V1 + V2 + V4" library(rms)

Running multiple linear regressions across several columns of a data frame in R

早过忘川 提交于 2019-12-11 08:07:45
问题 I have a dataset structured as such: enter image description here I would like to run linear regression models and ANOVA using V1, V2...etc. as the independent variables and the g column as the dependent variable in each case (i.e. lm(V1 ~ g), lm(V2 ~ g), and so forth). This would be straightforward except that these linear regressions need to be grouped by level in the pair column, such that, for example, my output contains lm(V1 ~ g) for all rows with pair 1.1 and lm(V1 ~ g) for all pairs 1

Possible compatibility issue with Keras, TensorFlow and scikit (tf.global_variables())

旧巷老猫 提交于 2019-12-11 08:02:01
问题 I'm trying to do a small test with my dataset on Keras Regressor (using TensorFlow), but I'm having a small issue. The error seems to be on the function cross_val_score from scikit. It starts on it and the last error message is: File "/usr/local/lib/python2.7/dist-packages/Keras-2.0.2-py2.7.egg/keras/backend/tensorflow_backend.py", line 298, in _initialize_variables variables = tf.global_variables() AttributeError: 'module' object has no attribute 'global_variables' My full code is basically