predict

robust standard errors in ggplot2

眉间皱痕 提交于 2019-11-30 23:18:56
I would like to plot a model with ggplot2. I have estimated a robust variance-covariance matrix which I would like to use when estimating the confidence interval. Can I tell ggplot2 to use my VCOV, or, alternatively, can I somehow force predict.lm to use my VCOV matrix? A dummy example: source("http://people.su.se/~ma/clmclx.R") df <- data.frame(x1 = rnorm(100), x2 = rnorm(100), y = rnorm(100), group = as.factor(sample(1:10, 100, replace=T))) lm1 <- lm(y ~ x1 + x2, data = df) coeftest(lm1) ## outputs coef.test, but can be modified to output VCOV clx(lm1, 1, df$group) It would be relatively

Apply predict() between data.frames within two lists

孤街醉人 提交于 2019-11-30 20:24:54
问题 Here some example data: df_1 = read.table(text = 'Year count var1 1951 12 380 1952 13 388 1953 11 400 1954 14 411 1955 14 422 1956 14 437 1957 12 451 1958 14 465 1959 13 481 1960 15 502 1961 17 522 1962 16 549 1963 14 572 1964 16 580', header = TRUE) df_2 = read.table(text = 'Year count var1 1951 12 380 1952 13 388 1953 11 400 1954 15 411 1955 14 422 1956 15 437 1957 11 451 1958 14 465 1959 13 481 1960 15 502 1961 20 522 1962 17 549 1963 14 572 1964 16 592', header = TRUE) lst1 = list(df_1,

warning when calculating predicted values

我的梦境 提交于 2019-11-30 20:19:21
working with a data frame x Date Val 1/1/2012 7 2/1/2012 9 3/1/2012 20 4/1/2012 24 5/1/2012 50 a <- seq(as.Date(tail(x, 1)$Date), by="month", length=5) a <- data.frame(a) x.lm <- lm(x$Val ~ x$Date) x.pre<-predict(x.lm, newdata=a) I am getting this erro: Warning message: 'newdata' had 5 rows but variable(s) found have 29 rows what am I doing wrong? here is the dput output: dput(x) structure(list(Date = structure(c(14610, 14641, 14669, 14700, 14730, 14761, 14791, 14822, 14853, 14883, 14914, 14944, 14975, 15006, 15034, 15065, 15095, 15126, 15156, 15187, 15218, 15248, 15279, 15309, 15340, 15371,

Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome)

杀马特。学长 韩版系。学妹 提交于 2019-11-30 19:39:16
I've fitted a logistic regression model that predicts the a binary outcome vs from mpg ( mtcars dataset). The plot is shown below. How can I determine the mpg value for any particular vs value? For example, I'm interested in finding out what the mpg value is when the probability of vs is 0.50. Appreciate any help anyone can provide! model <- glm(vs ~ mpg, data = mtcars, family = binomial) ggplot(mtcars, aes(mpg, vs)) + geom_point() + stat_smooth(method = "glm", method.args = list(family = "binomial"), se = FALSE) The easiest way to calculate predicted values from your model is with the predict

Predicting Missing Words in a sentence - Natural Language Processing Model [closed]

随声附和 提交于 2019-11-30 19:35:43
问题 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 9 months ago . I have the sentence below : I want to ____ the car because it is cheap. I want to predict the missing word ,using an NLP model. What NLP model shall I use? Thanks. 回答1: TL;DR Try this out: https://github.com/huggingface/pytorch-pretrained-BERT First you have to set it up, properly with pip install -U pytorch

predict method for felm from lfe package

无人久伴 提交于 2019-11-30 17:10:11
Does anyone have a nice clean way to get predict behavior for felm models? library(lfe) model1 <- lm(data = iris, Sepal.Length ~ Sepal.Width + Species) predict(model1, newdata = data.frame(Sepal.Width = 3, Species = "virginica")) # Works model2 <- felm(data = iris, Sepal.Length ~ Sepal.Width | Species) predict(model2, newdata = data.frame(Sepal.Width = 3, Species = "virginica")) # Does not work As a workaround, you could combine felm , getfe , and demeanlist as follows: library(lfe) lm.model <- lm(data=demeanlist(iris[, 1:2], list(iris$Species)), Sepal.Length ~ Sepal.Width) fe <- getfe(felm

Regression (logistic) in R: Finding x value (predictor) for a particular y value (outcome)

僤鯓⒐⒋嵵緔 提交于 2019-11-30 03:32:37
问题 I've fitted a logistic regression model that predicts the a binary outcome vs from mpg ( mtcars dataset). The plot is shown below. How can I determine the mpg value for any particular vs value? For example, I'm interested in finding out what the mpg value is when the probability of vs is 0.50. Appreciate any help anyone can provide! model <- glm(vs ~ mpg, data = mtcars, family = binomial) ggplot(mtcars, aes(mpg, vs)) + geom_point() + stat_smooth(method = "glm", method.args = list(family =

Error in Python script “Expected 2D array, got 1D array instead:”?

半世苍凉 提交于 2019-11-30 02:38:44
I'm following this tutorial to make this ML prediction: import numpy as np import matplotlib.pyplot as plt from matplotlib import style style.use("ggplot") from sklearn import svm x = [1, 5, 1.5, 8, 1, 9] y = [2, 8, 1.8, 8, 0.6, 11] plt.scatter(x,y) plt.show() X = np.array([[1,2], [5,8], [1.5,1.8], [8,8], [1,0.6], [9,11]]) y = [0,1,0,1,0,1] X.reshape(1, -1) clf = svm.SVC(kernel='linear', C = 1.0) clf.fit(X,y) print(clf.predict([0.58,0.76])) I'm using Python 3.6 and I get error "Expected 2D array, got 1D array instead:" I think the script is for older versions, but I don't know how to convert

What is the difference between lm(offense$R ~ offense$OBP) and lm(R ~ OBP)?

送分小仙女□ 提交于 2019-11-29 14:12:00
I am trying to use R to create a linear model and use that to predict some values. The subject matter is baseball stats. If I do this: obp <- lm(offense$R ~ offense$OBP) predict(obp, newdata=data.frame(OBP=0.5), interval="predict") I get the error: Warning message: 'newdata' had 1 row but variables found have 20 rows. However, if I do this: attach(offense) obp <- lm(R ~ OBP) predict(obp, newdata=data.frame(OBP=0.5), interval="predict") It works as expected and I get one result. What is the difference between the two? If I just print OBP and offense$OBP, they look the same. In the first case,

predict.svm does not predict new data

半腔热情 提交于 2019-11-29 07:22:39
unfortunately I have problems using predict() in the following simple example: library(e1071) x <- c(1:10) y <- c(0,0,0,0,1,0,1,1,1,1) test <- c(11:15) mod <- svm(y ~ x, kernel = "linear", gamma = 1, cost = 2, type="C-classification") predict(mod, newdata = test) The result is as follows: > predict(mod, newdata = test) 1 2 3 4 <NA> <NA> <NA> <NA> <NA> <NA> 0 0 0 0 0 1 1 1 1 1 Can anybody explain why predict() only gives the fitted values of the training sample (x,y) and does not care about the test-data? Thank you very much for your help! Richard It looks like this is because you misuse the