regression

GAM with “gp” smoother: predict at new locations

不羁的心 提交于 2020-01-30 08:04:40
问题 I am using the following geoadditive model library(gamair) library(mgcv) data(mack) mack$log.net.area <- log(mack$net.area) gm2 <- gam(egg.count ~ s(lon,lat,bs="gp",k=100,m=c(2,10,1)) + s(I(b.depth^.5)) + s(c.dist) + s(temp.20m) + offset(log.net.area), data = mack, family = tw, method = "REML") How can I use it to predict the value of egg.count at new locations (lon/lat) where I don't have covariate data, as in kriging ? For example say I want to predict egg.count at these new locations lon

R: repeat linear regression for all variables and save results in a new data frame

为君一笑 提交于 2020-01-25 06:46:12
问题 I have a data frame named “dat” with 10 numeric variables (var1, var2,var3,var4 , var5,…var 10), each with several observations… dat var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 1 12 5 18 19 12 17 11 16 18 10 2 3 2 10 6 13 17 11 16 18 10 3 13 15 14 13 1 17 11 16 18 10 4 17 11 16 18 10 17 11 16 18 10 5 9 13 8 8 7 17 11 16 18 10 6 15 6 20 17 3 17 11 16 18 10 7 12 5 18 19 12 17 11 16 18 10 8 3 2 10 6 13 17 11 16 18 10 9 13 15 14 13 1 17 11 16 18 10 ... I would like to write a code to

R: repeat linear regression for all variables and save results in a new data frame

老子叫甜甜 提交于 2020-01-25 06:46:07
问题 I have a data frame named “dat” with 10 numeric variables (var1, var2,var3,var4 , var5,…var 10), each with several observations… dat var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 1 12 5 18 19 12 17 11 16 18 10 2 3 2 10 6 13 17 11 16 18 10 3 13 15 14 13 1 17 11 16 18 10 4 17 11 16 18 10 17 11 16 18 10 5 9 13 8 8 7 17 11 16 18 10 6 15 6 20 17 3 17 11 16 18 10 7 12 5 18 19 12 17 11 16 18 10 8 3 2 10 6 13 17 11 16 18 10 9 13 15 14 13 1 17 11 16 18 10 ... I would like to write a code to

Ridge regression in glmnet in R; Calculating VIF for different lambda values using glmnet package

匆匆过客 提交于 2020-01-24 13:04:20
问题 I have a set of multicollinear variables and I'm trying to use ridge regression to tackle that. I am using the GLMNET package in R with alpha = 0 (for ridge regression). library(glmnet) I have a sequence of lambda values; and I am choosing the best lambda value through cv.glmnet lambda <- 10^seq(10, -2, length = 100) -- creating model matrix and assigning the y variable x <- model.matrix(dv ~ ., datamatrix) [,-1] y <- datamatrix$dv -- Using cross validation to determine the best lambda and

Ridge regression in glmnet in R; Calculating VIF for different lambda values using glmnet package

心已入冬 提交于 2020-01-24 13:04:04
问题 I have a set of multicollinear variables and I'm trying to use ridge regression to tackle that. I am using the GLMNET package in R with alpha = 0 (for ridge regression). library(glmnet) I have a sequence of lambda values; and I am choosing the best lambda value through cv.glmnet lambda <- 10^seq(10, -2, length = 100) -- creating model matrix and assigning the y variable x <- model.matrix(dv ~ ., datamatrix) [,-1] y <- datamatrix$dv -- Using cross validation to determine the best lambda and

negative value for “mean_squared_error”

◇◆丶佛笑我妖孽 提交于 2020-01-23 12:22:08
问题 I am using scikit and using mean_squared_error as a scoring function for model evaluation in cross_val_score. rms_score = cross_validation.cross_val_score(model, X, y, cv=20, scoring='mean_squared_error') I am using mean_squared_error as it is a regression problem and the estimators (model) used are lasso , ridge and elasticNet . For all these estimators, I am getting rms_score as negative values. How is it possible, given the fact that the differences in y values are squared. 回答1: You get

R2 values - dplyr and broom

ε祈祈猫儿з 提交于 2020-01-22 19:41:27
问题 I am using the dplyr and broom combination (per below) and following Fitting several regression models with dplyr to extract the regression coefficients of regressions by group. However - i am also interested in the R2 value of each individual regression (not only for the total model). i have tried to play wiht the augment and glance functions - but have not been able to extract the R2 values. is there an easy way to do this? Many thanks in advance! library(dplyr) library(broom) df.h = data

Why do I get NA coefficients and how does `lm` drop reference level for interaction

别来无恙 提交于 2020-01-21 07:26:06
问题 I am trying to understand how R determines reference groups for interactions in a linear model. Consider the following: df <- structure(list(id = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1", "2", "3", "4", "5"), class = "factor"), year = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1", "2"),

Is there a function or package which will simulate predictions for an object returned from lm()?

 ̄綄美尐妖づ 提交于 2020-01-21 03:12:04
问题 Is there a single function, similar to "runif", "rnorm" and the like which will produce simulated predictions for a linear model? I can code it on my own, but the code is ugly and I assume that this is something someone has done before. slope = 1.5 intercept = 0 x = as.numeric(1:10) e = rnorm(10, mean=0, sd = 1) y = slope * x + intercept + e fit = lm(y ~ x, data = df) newX = data.frame(x = as.numeric(11:15)) What I'm interested in is a function that looks like the line below: sims = rlm(1000,

How to change points and add a regression to a cloudplot (using R)?

江枫思渺然 提交于 2020-01-19 04:59:58
问题 To make clear what I'm asking I've created an easy example. Step one is to create some data: gender <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2),labels = c("male", "female")) numberofdrugs <- rpois(84, 50) + 1 geneticvalue <- rpois(84,75) death <- rpois(42,50) + 15 y <- data.frame(death, numberofdrugs, geneticvalue, gender) So these are some random dates merged to one data.frame . So from these dates I'd like to plot a cloud where I can differ between the males and females and where I