regression

How to extract the p-value for the slope from an ols object in R

强颜欢笑 提交于 2019-12-12 16:49:23
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 7 years ago . If I do data(mtcars) m1 <- lm(mpg ~ cyl, data= mtcars, x= TRUE, y= TRUE) then I can extract the p-value for the slope using summary(m1)$coefficients[2, 4] . But if I do library(rms) data(mtcars) m2 <- ols(mpg ~ cyl, data= mtcars, x= TRUE, y= TRUE) what do I need to do to extract the p-value for the slope? 回答1: You can use the corresponding extractor function, but you need to

vectorization of “cumulative” regression

為{幸葍}努か 提交于 2019-12-12 15:34:54
问题 I have data dat <- data.frame(t=1:100,y=rnorm(100),x1=rnorm(100)),x2=rnorm(100)) where t gives points in time. I would like to regress y on x1 and x2 at each point in time based on the preceeding points in time. I could create a loop reg <- matrix(rep(NA,3*nrow(dat),ncol=3) for(i in 11:nrow(dat)){ reg[i,] <- coefficients(lm(y ~ x1 + x2, data=dat[1:i,])) } but I wonder whether anyone knows a way to vectorize this, perhaps using data.table . 回答1: We can use a non-equi-self-join to get the table

ggplot2: Plotting regression lines with different intercepts but with same slope

℡╲_俬逩灬. 提交于 2019-12-12 14:06:52
问题 I want to plot regression lines with different intercepts but with the same slope. With the following ggplot2 code, I can plot regression lines with different intercepts and different slopes. But could not figured out how to draw regression lines with different different intercepts but the same slopes. library(ggplot2) ggplot(data=df3, mapping=aes(x=Income, y=Consumption, color=Gender)) + geom_point() + geom_smooth(data=df3, method = "lm", se=FALSE, mapping=aes(x=Income, y=Consumption))

Custom Link function works for GLM but not mgcv GAM

老子叫甜甜 提交于 2019-12-12 13:15:49
问题 Apologies if the answer is obvious but I've spent quite some time trying to use a custom link function in mgcv.gam In short, I want to use a modified probit link from package psyphy ( I want to use psyphy.probit_2asym, I call it custom_link ) I can create a {stats}family object with this link and use it in the 'family' argument of glm. m <- glm(y~x, family=binomial(link=custom_link), ... ) It does not work when used as an argument for {mgcv}gam m <- gam(y~s(x), family=binomial(link=custom

Orthogonal matching pursuit regression - am I using it wrong?

别等时光非礼了梦想. 提交于 2019-12-12 12:23:52
问题 I am trying out this method as a regularized regression, as an alternative to lasso and elastic net. I have 40k data points and 40 features. Lasso selects 5 features, and orthogonal matching pursuit selects only 1. What could be causing this? Am I using omp the wrong way? Perhaps it is not meant to be used as a regression. Please let me know if you can thing of anything else I may be doing wrong. 回答1: Orthogonal Matching Pursuit seems a bit broken, or at least very sensitive to input data, as

R: How to read Nomograms to predict the desired variable

我与影子孤独终老i 提交于 2019-12-12 11:20:09
问题 I am using Rstudio. I have created nomograms using function nomogram from package rms using following code (copied from the example code of the documentation): library(rms) n <- 1000 # define sample size set.seed(17) # so can reproduce the results age <- rnorm(n, 50, 10) blood.pressure <- rnorm(n, 120, 15) cholesterol <- rnorm(n, 200, 25) sex <- factor(sample(c('female','male'), n,TRUE)) # Specify population model for log odds that Y=1 L <- .4*(sex=='male') + .045*(age-50) + (log(cholesterol

ValueError: A value in x_new is below the interpolation range

你说的曾经没有我的故事 提交于 2019-12-12 10:40:54
问题 This is a scikit-learn error that I get when I do my_estimator = LassoLarsCV(fit_intercept=False, normalize=False, positive=True, max_n_alphas=1e5) Note that if I decrease max_n_alphas from 1e5 down to 1e4 I do not get this error any more. Anyone has an idea on what's going on? The error happens when I call my_estimator.fit(x, y) I have 40k data points in 40 dimensions. The full stack trace looks like this File "/usr/lib64/python2.7/site-packages/sklearn/linear_model/least_angle.py", line

How obtain the intercept of the PLS-Regression (sklearn)

你离开我真会死。 提交于 2019-12-12 10:24:16
问题 The PLS regression using sklearn gives very poor prediction results. When I get the model I can not find the way to find the "intercept". Perhaps this affects the prediction of the model? The matrix of scores and loadings are fine. The arrangement of the coefficients also. In any case, how do I get the intercept using the attributes already obtained? This code throws the coefficients of the variables. from pandas import DataFrame from sklearn.cross_decomposition import PLSRegression X =

Extracting the terminal nodes of each tree associated with a new observation

寵の児 提交于 2019-12-12 10:20:12
问题 I would like to extract the terminal nodes of the random forest R implementation. As I have understood random forest, you have a sequence of orthogonal trees. When you predict a new observation (In regression), it enters all these trees and then you average the prediction of each individual tree. If I wanted to not average but maybe do a linear regression with these corresponding observations I would need, say, a list of the observations that are "associated" with this new observation. I have

Interpreting the output of glm for Poisson regression [closed]

风流意气都作罢 提交于 2019-12-12 10:14:21
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Consider the following: foo = 1:10 bar = 2 * foo glm(bar ~ foo, family=poisson) I get results Coefficients: (Intercept) foo 1.1878 0.1929 Degrees of Freedom: 9 Total (i.e. Null); 8 Residual Null Deviance: 33.29 Residual Deviance: 2.399 AIC: 47.06 From the explanation on this page, it seems like the coefficient