regression

Change colours in visreg2D regression plot

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 02:54:45
问题 A great way to visualise the results of a regression in R is the visreg package. I particularly like the plots that show an interaction with different shades of two colours: library(visreg) fit.heat <- lm(Ozone ~ Solar.R + Wind + Temp, data = airquality) visreg2d(fit.heat, "Wind", "Temp", plot.type = "image") (from the visreg documentation) The two colours used are red and blue. Question How can I change the colors? Shades of red and blue don't look too well in black and white print, red and

Pandas: Key Error when implementing a Panel OLS

旧街凉风 提交于 2019-12-13 02:34:12
问题 I have the following dataframe: url='https://raw.githubusercontent.com/108michael/ms_thesis/master/crsp.dime.mpl.df.1' df=pd.read_csv(url, index_col=0) df=df.pivot_table(index='date',columns='cid', fill_value=0,aggfunc=np.mean) df=df.T.to_panel() df=df.transpose(2,0,1) df <class 'pandas.core.panel.Panel'> Dimensions: 505 (items) x 10 (major_axis) x 19 (minor_axis) Items axis: N00000010 to N00035686 Major_axis axis: 2005 to 2014 Minor_axis axis: candcfscore.dyn_static to dir_ind

Probability predictions with cumulative link mixed models

倖福魔咒の 提交于 2019-12-13 02:21:41
问题 I am trying to fit cumulative link mixed models with the ordinal package but there is something I do not understand about obtaining the prediction probabilities. I use the following example from the ordinal package: library(ordinal) data(soup) ## More manageable data set: dat <- subset(soup, as.numeric(as.character(RESP)) <= 24) dat$RESP <- dat$RESP[drop=TRUE] m1 <- clmm2(SURENESS ~ PROD, random = RESP, data = dat, link="logistic", Hess = TRUE,doFit=T) summary(m1) str(dat) Now I am trying to

glmnet training throws error on x,y dataframe arguments: am I using it wrong?

坚强是说给别人听的谎言 提交于 2019-12-13 02:16:07
问题 I'm trying to learn a penalized logistic regression method with glmnet. I'm trying to predict if a car from the mtcars example data will have an automatic transmission or manual. I think my code is pretty straightforward, but I seem to be getting an error: This first block simply splits mtcars into an 80% train set and a 20% test set library(glmnet) attach(mtcars) smp_size <- floor(0.8 * nrow(mtcars)) set.seed(123) train_ind <- sample(seq_len(nrow(mtcars)), size=smp_size) train <- mtcars

NLS Function By Group

☆樱花仙子☆ 提交于 2019-12-12 23:30:18
问题 I have a dataset where I want to apply non linear least squares by group. This is a continuation to my previous question: NLS Function - Number of Iterations Exceeds max The dataset looks like this: df x y GRP 0 0 1 426 9.28 1 853 18.5 1 1279 27.8 1 1705 37.0 1 2131 46.2 1 0 0 2 450 7.28 2 800 16.5 2 1300 30.0 2 2000 40.0 2 2200 48.0 2 If I were to do this with one group it would be like this: df1<-filter(df, GRP==1) a.start <- max(df1$y) b.start <- 1e-06 control1 <- nls.control(maxiter=

Toy R function for solving ordinary least squares by singular value decomposition

99封情书 提交于 2019-12-12 22:17:49
问题 I'm trying to write a functions for multiple regression analysis ( y = Xb + e ) using a singular value decomposition for matrices. y and X must be the input and regression coefficients vector b , the residual vector e and variance accounted for R2 as output. Beneath is what I have so far and I'm totally stuck. The labels part of the weight also gives me an error. What is this labels part? Can anybody give me some tips to help me proceed? Test <- function(X, y) { x <- t(A) %*% A duv <- svd(x)

Plotting conditional density of prediction after linear regression

情到浓时终转凉″ 提交于 2019-12-12 20:09:30
问题 This is my data frame: data <- structure(list(Y = c(NA, -1.793, -0.642, 1.189, -0.823, -1.715, 1.623, 0.964, 0.395, -3.736, -0.47, 2.366, 0.634, -0.701, -1.692, 0.155, 2.502, -2.292, 1.967, -2.326, -1.476, 1.464, 1.45, -0.797, 1.27, 2.515, -0.765, 0.261, 0.423, 1.698, -2.734, 0.743, -2.39, 0.365, 2.981, -1.185, -0.57, 2.638, -1.046, 1.931, 4.583, -1.276, 1.075, 2.893, -1.602, 1.801, 2.405, -5.236, 2.214, 1.295, 1.438, -0.638, 0.716, 1.004, -1.328, -1.759, -1.315, 1.053, 1.958, -2.034, 2.936,

R: Clustered robust standard errors using miceadds lm.cluster - error with subset and weights

空扰寡人 提交于 2019-12-12 18:14:02
问题 I am trying to use the lm.cluster function in the package miceadds to get robust clustered standard errors for a multiply imputed dataset. I am able to get the standard version of it to run but I get the following error when I try to add a subset or weights: Error in eval(substitute(subset), data, env) : ..1 used in an incorrect context, no ... to look in Example that works without subset or weights: require("mice") require("miceadds") data(data.ma01) # imputation of the dataset: use six

R: Error in contrasts when fitting linear models with `lm`

徘徊边缘 提交于 2019-12-12 17:16:47
问题 I've found Error in contrasts when defining a linear model in R and have followed the suggestions there, but none of my factor variables take on only one value and I am still experiencing the same issue. This is the dataset I'm using: https://www.dropbox.com/s/em7xphbeaxykgla/train.csv?dl=0. This is the code I'm trying to run: simplelm <- lm(log_SalePrice ~ ., data = train) #Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : # contrasts can be applied only to factors with 2

Machine Learning:十大机器学习算法

纵然是瞬间 提交于 2019-12-12 16:52:23
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 机器学习算法大致可以分为三类: 监督学习算法 (Supervised Algorithms) :在监督学习训练过程中,可以由训练数据集学到或建立一个模式(函数 / learning model),并依此模式推测新的实例。该算法要求特定的输入/输出,首先需要决定使用哪种数据作为范例。例如,文字识别应用中一个手写的字符,或一行手写文字。主要算法包括神经网络、支持向量机、最近邻居法、朴素贝叶斯法、决策树等。 无监督学习算法 (Unsupervised Algorithms) :这类算法没有特定的目标输出,算法将数据集分为不同的组。 强化学习算法 (Reinforcement Algorithms) :强化学习普适性强,主要基于决策进行训练,算法根据输出结果(决策)的成功或错误来训练自己,通过大量经验训练优化后的算法将能够给出较好的预测。类似有机体在环境给予的奖励或惩罚的刺激下,逐步形成对刺激的预期,产生能获得最大利益的习惯性行为。在运筹学和控制论的语境下,强化学习被称作“近似动态规划”(approximate dynamic programming,ADP)。 基本的机器学习算法: 线性回归算法 Linear Regression 支持向量机算法 (Support Vector Machine,SVM) 最近邻居/k