[R] linearHypothesis
Dear R-users, I am using the R-function "linearHypothesis" to test if the sum of all parameters, but the intercept, in a multiple linear regression is different from zero. I wonder if it is statistically valid to use the linearHypothesis-function for this? Below is a reproducible example in R. A multiple regression: y = beta0*t0+beta1*t1+beta2*t2+beta3*t3+beta4*t4 It seems to me that the linearHypothesis function does the calculation as an F-test on the extra residuals when going from the starting model to a 'subset' model, although all variables in the 'subset' model differ from the variables in the starting model. I normally think of a subset model as a model built on the same input data as the starting model but one variable. Hence, is this a valid calculation? Thanks in advance,Johan # R-code: y <- c(101133190,96663050,106866486,97678429,83212348,75719714,77861937,74018478,82181104,68667176,64599495,62414401,63534709,58571865,65222727,60139788, 63355011,57790610,55214971,55535484,55759192,49450719,48834699,51383864,51250871,50629835,52154608,54636478,54942637) data <- data.frame(y,"t0"=1,"t1"=1990:2018,"t2"=c(rep(0,12),1:17),"t3"=c(rep(0,17),1:12),"t4"=c(rep(0,23),1:6)) model <- lm(y~t0+t1+t2+t3+t4+0,data=data) linearHypothesis(model,"t1+t2+t3+t4=0",test=c("F")) # Reproduce the result from linearHypothesis: # beta1+beta2+beta3+beta4=0 -> beta4=-(beta1+beta2+beta3) -> # y=beta0+beta1*t1+beta2*t2+beta3*t3-(beta1+beta2+beta3)*t4 # y = beta0'+beta1'*(t1-t4)+beta2'*(t2-t4)+beta3'*(t3-t4) data$t1 <- data$t1-data$t4 data$t2 <- data$t2-data$t4 data$t3 <- data$t3-data$t4 model_reduced <- lm(y~t0+t1+t2+t3+0,data=data) anova(model_reduced,model) -- Johan Lassen "In the cities people live in time - in the mountains people live in space" (Budistisk munk). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Isolation forest using "solitude" package: help to predict
Dear community, I would like to know if someone can help clarifying how to predict anomaly scores on new data sets using the "solitude" package. A simple model can be trained using: library(solitude) # Training the model: iris_train <- iris[1:100, ] model <- isolation_forest(iris_train[, 1:4], seed = 100,num.trees=100,importance="none") # The anomaly scores of a new test data set can be calculated by iris_test <- iris[100:150, ] predicted_anomalies <- predict(mo, iris_test[, 1:4],type="anomaly_score") #The challenge is how to predict the anomaly scores for a data set with less observations than the #number of observations in the training data set. # Example: using a subset of just 11 observations as compared to the 51 observations results in anomaly scores that are smaller: iris_test <- iris[100:110, ] predicted_anomalies <- predict(mo, iris_test[, 1:4],type="anomaly_score") Anyone knows how to predict "normalised (with respect to sample size)" anomaly scores using the solitude package for R? Thanks in advance! Johan -- Johan Lassen "In the cities people live in time - in the mountains people live in space" (Budistisk munk). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Introductory courses in R in Denmark?
Dear R-forum! I would like to hear if someone know off some good introductory classes in Denmark? E.g. one week course with teaching in basic R (how to read/export in data into/from R with emphasis on txt, csv. and database, how to do basic operations on data frames and vectors, how to plot data and so on). Thanks in advance! -- Johan Lassen In the cities people live in time - in the mountains people live in space (Budistisk munk). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R and libre office base
Dear community . I would like to connect r to libre office base. Does anyone know if and how this can be done? I think of the pendant to rodbc for libre office. I am using windows 7. Thanks in advance and best regards johan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RODBC-Error-sqlSave
Dear R-community, After repeating the sqlSave-command 3 times on a dataframe (of size 13149 rows * 5 columns) to my MS-Access database I get the following error: *Error in sqlSave(channel, eksport_transp_acc_2, transp_acc_scenarier, : unable to append to table transp_acc_scenarier* ** This means that the first 2 savings are completed, but the third-one is somehow not. I have an idea that perhaps it is due to some out-of-memory problem. My PC has 2 CPUs, 1.83 G Hz, 0.99 GB RAM. Have anyone got some idea of what causes and solves the problem? I have tried also with the function *gc()*, but without success. Thanks in advance, Best regards, Johan PS: I use the following code, where the file *eksport_transp_acc_2_rbind.csv* is of size 13149*5: *library(RODBC)* ** *eksport_transp_acc_2 - read.table(file = results/csv/eksport_transp_acc_2_rbind.csv, sep =;, header = T)* ** *sqlSave(channel,eksport_transp_acc_2, transp_acc_scenarier,append = T,fast = F,rownames = F) * -- Johan Lassen In the cities people live in time - in the mountains people live in space [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RODBC-Error-sqlSave
Thank you so much for pointing on this obvious check of the MS Access database! Inspired, I tried to import the csv-file directly into the MS Access database and I encountered an Error saying (freely translated from Danish) : Cannot find search key. The MS Access database is in MS Access-2000 format and I run MS office 2007 on my machine. Hence I tried to make a new MS Access-database in 2002-2003 format and did the same operations in R. With this new set-up for the database I had no problems at all saving the large dataframe from R to the new database. It did the saving of even much larger dataframes quickly. So somehow, setting the database up in 2002-2003 format solved the problem for me. Thank you very much! 2010/5/16 Orvalho Augusto orvaq...@gmail.com Let us see if it is a R issue. Try this: Read the CSV on Ms Access directly. It is an importation on MsAccess. If you succeed we will check R then. Caveman On Sun, May 16, 2010 at 11:48 AM, Johan Lassen johanlas...@gmail.com wrote: Dear R-community, After repeating the sqlSave-command 3 times on a dataframe (of size 13149 rows * 5 columns) to my MS-Access database I get the following error: *Error in sqlSave(channel, eksport_transp_acc_2, transp_acc_scenarier, : unable to append to table transp_acc_scenarier* ** This means that the first 2 savings are completed, but the third-one is somehow not. I have an idea that perhaps it is due to some out-of-memory problem. My PC has 2 CPUs, 1.83 G Hz, 0.99 GB RAM. Have anyone got some idea of what causes and solves the problem? I have tried also with the function *gc()*, but without success. Thanks in advance, Best regards, Johan PS: I use the following code, where the file *eksport_transp_acc_2_rbind.csv* is of size 13149*5: *library(RODBC)* ** *eksport_transp_acc_2 - read.table(file = results/csv/eksport_transp_acc_2_rbind.csv, sep =;, header = T)* ** *sqlSave(channel,eksport_transp_acc_2, transp_acc_scenarier,append = T,fast = F,rownames = F) * -- Johan Lassen In the cities people live in time - in the mountains people live in space [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Johan Lassen In the cities people live in time - in the mountains people live in space (Budistisk munk). [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem using the source-function within R-functions
Hi Giovanni, Thanks for your reply. I can make the function work after parsing the code directly into R. The problem arise after compiling the function into a package and then calling the function, because the files inside source() seems to be missing. I tried to include the sourced files in the argument code_files of the function package.skeleton. The files are brought correctly to the package but when running the generated package then the files produce an error due to variables that are not defined. There may be no way around other than copying the content of the sourced files into the file where the function is defined? - in this way the definition of the function is all written in one file, but the organization of the code-sections is worse than when using the source()-function... Best regards, Johan 2009/10/20 Giovanni Petris gpet...@uark.edu The problem probably lies in the source-ing part: look at getwd() setwd() HTH, Giovanni Date: Tue, 20 Oct 2009 13:00:02 +0200 From: Johan Lassen jle...@gmail.com Sender: r-help-boun...@r-project.org Precedence: list DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; --===0554064772== Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 1477 Dear R community, You may have the solution to how to construct a function using the function source() to build the function; i.e. myfunction - function(...){ source('file1.r') source('file2.r') } After compiling and installing the myfunction in R, then calling the myfunction gives an error because the content of 'file1.r' and 'file2.r' seems to be missing. Anyone has the trick to overcome this problem? Thanks in advance! best wishes, Johan PS: My function is: run_accumm_value - function(ind_noder_0, ind_loc_val,ind_retention,downstream){ ## Preprocessing of looping calculations: koersel_uden_ret - length(unique(ind_noder_0$oplid)) opsaml_b_0_2 - numeric(koersel_uden_ret) opsaml_b_0_2_1 - numeric(koersel_uden_ret) opsaml_b_0_2_2 - seq(1:koersel_uden_ret) ## Preprocessing of topology and local values to be summed: source('preproces_topology.r', local =3D T) source('preproces_loc_val.r', local =3D T) # Loop for each grouping factor (column in ind_noder_0: oplid): for(j in 1:koersel_uden_ret){ source('matrix_0.r', local =3D T) source('matrix.r', local =3D T) source('local_value.r', local =3D T) source('fordeling.r', local =3D T) source('fordeling_manuel.r', local =3D T) source('local_ret.r', local =3D T) source('Ax=3Db.r', local =3D T) source('opsamling_x_0_acc.r', local =3D T) } source('opsamling_b_1.r', local =3D T) opsaml_b_2 } --=20 Johan Lassen Environment Center Nyk=F8bing F Denmark [[alternative HTML version deleted]] --===0554064772== Content-Type: text/plain; charset=us-ascii MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. --===0554064772==-- -- Giovanni Petris gpet...@uark.edu Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ -- Johan Lassen Environment Center Nykøbing F Denmark [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem using the source-function within R-functions
Dear R community, You may have the solution to how to construct a function using the function source() to build the function; i.e. myfunction - function(...){ source('file1.r') source('file2.r') } After compiling and installing the myfunction in R, then calling the myfunction gives an error because the content of 'file1.r' and 'file2.r' seems to be missing. Anyone has the trick to overcome this problem? Thanks in advance! best wishes, Johan PS: My function is: run_accumm_value - function(ind_noder_0, ind_loc_val,ind_retention,downstream){ ## Preprocessing of looping calculations: koersel_uden_ret - length(unique(ind_noder_0$oplid)) opsaml_b_0_2 - numeric(koersel_uden_ret) opsaml_b_0_2_1 - numeric(koersel_uden_ret) opsaml_b_0_2_2 - seq(1:koersel_uden_ret) ## Preprocessing of topology and local values to be summed: source('preproces_topology.r', local = T) source('preproces_loc_val.r', local = T) # Loop for each grouping factor (column in ind_noder_0: oplid): for(j in 1:koersel_uden_ret){ source('matrix_0.r', local = T) source('matrix.r', local = T) source('local_value.r', local = T) source('fordeling.r', local = T) source('fordeling_manuel.r', local = T) source('local_ret.r', local = T) source('Ax=b.r', local = T) source('opsamling_x_0_acc.r', local = T) } source('opsamling_b_1.r', local = T) opsaml_b_2 } -- Johan Lassen Environment Center Nykøbing F Denmark [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.