gmane.comp.lang.r.general
http://blog.gmane.org/gmane.comp.lang.r.general
hourly11901-01-01T00:00+00:00Gmanehttp://gmane.org/img/gmane-25t.png
http://gmane.org
Help w/ variable names in loop with lmer
http://comments.gmane.org/gmane.comp.lang.r.general/318893
<pre>Hi, R users-
I'm estimating random effects models with cross-level interactions; I want
to interact each of a vector of level-1 variables with each of a vector of
level-2 variables. Here's the code:
====================
#create data frame with level-1 variables
k <- as.data.frame(cbind(robo, asalto, secuestro, asesinato))
#create data frame with level-2 variables
l <- as.data.frame(cbind(IDH_IDH, IDH_ingpc, eco_pb, IM_indice, tasa_robo,
hom_tasa, totdelitos1, totdelitos2, total, pri, pan, prd))
#get cross-level interactions
for (i in 1:length(k)) {
for (j in 1:length(l)) {
print(summary(lmer(hrprotcrim ~ k[,i]*l[,j] + (k[,i] | Municipio))))
}
}
======================
The code works and produces 48 (4 level-1 x 12 level-2) sets of output.
The problem is, the output is illegible because instead of the variable
names, I get the indices:
[output]
==================================
Linear mixed model fit by REML ['lmerMod']
Formula: hrprotcrim ~ k[, i] * l[, j] + (k[, i] | Municipio)
REML criterion at co</pre>David Crow2015-03-29T21:59:59generating phi using function()
http://comments.gmane.org/gmane.comp.lang.r.general/318889
<pre>Hi everybody,
I am trying to generate the formula shown in the attachment. My formula so far looks as follows:
phi <- function(w1, w2, j, k, K){
zaehler <- (k/K)^(w1-1)*(1-k/K)^(w2-1)
nenner <- sum( ((1:K)/K)^(w1-1)*(1-(1:K)/K)^(w2-1))
return( zaehler/nenner )
}
Unfortunately something must be wrong here as I get the following message when running a midas regression
m22.phi<- midas_r(rv~mls(rvh,1:max.lag+h1,1,phi), start = list(rvh=c(1,1)))
Error in phi(c(1, 1), 44L, 1) : argument "K" is missing, with no default
Called from: .rs.breakOnError(TRUE)
Browse[1]> K<-125
Browse[1]> 125
Could anybody look into my phi formula and tell me what is wrong with it?
Thanks in advance.
</pre>T.Riedle2015-03-29T12:59:48Error in lm() with very small (close to zero) regressor
http://comments.gmane.org/gmane.comp.lang.r.general/318872
<pre>Hello everybody,
I have encountered the following problem with lm():
When running lm() with a regressor close to zero - of the order e-10, the
value of the estimate is of huge absolute value , of order millions.
However, if I write the formula of the OLS estimator, in matrix notation:
pseudoinverse(t(X)*X) * t(X) * y , the results are correct, meaning the
estimate has value 0.
here is the code:
y <- rnorm(n_obs, 10,2.89)
x1 <- rnorm(n_obs, 0.00000000000001235657,0.000000000000000045)
x2 <- rnorm(n_obs, 10,3.21)
X <- cbind(x1,x2)
bFE <- lm(y ~ x1 + x2)
bFE
bOLS <- pseudoinverse(t(X) %*% X) %*% t(X) %*% y
bOLS
Note: I am applying a deviation from the mean projection to the data, that
is why I have some regressors with such small values.
Thank you for any help!
Raluca
--
View this message in context: http://r.789695.n4.nabble.com/Error-in-lm-with-very-small-close-to-zero-regressor-tp4705185.html
Sent from the R help mailing list archive at Nabble.com.
</pre>RiGui2015-03-27T23:32:26cannot load midasr package
http://comments.gmane.org/gmane.comp.lang.r.general/318871
<pre>Dear Sirs,
I am trying to implement the MIDAS regression but I cannot load the midasr package.
When I load the package I get following message:
Loading required package: sandwich
Loading required package: optimx
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
there is no package called 'Rcpp'
Error: package 'optimx' could not be loaded
Error: could not find function "mls"
I am using version 3.1.3 and 3.0.2 but neither version works. When I was working with it last week everything was okay but now it does not work anymore. What can I do?
Thanks for your help.
Kind regards,
T. Riedle
[[alternative HTML version deleted]]
</pre>T.Riedle2015-03-28T09:04:04multiple break in univariate series
http://comments.gmane.org/gmane.comp.lang.r.general/318870
<pre>Hello
Any one knows multiple break test for univariate series ?
</pre>Temel İspanyolca2015-03-27T23:41:35hash - extract key values
http://comments.gmane.org/gmane.comp.lang.r.general/318860
<pre>Hi,
I was trying to use hash, but can't seem to get the keys from the hash.
According to the hash documentation ('hash' package pdf, the following
should work:
[1] "hash"
attr(,"package")
[1] "hash"
[1] 1
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘keys’ for signature
‘"hash"’
How can I get the keys for my hash?
thanks!
[[alternative HTML version deleted]]
______________________________________________
R-help< at >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.</pre>Brian Smith2015-03-27T23:39:41Categorizing by month
http://comments.gmane.org/gmane.comp.lang.r.general/318852
<pre>Hi everyone,
I'm trying to categorize by month in R. How can I do this if my dates are in
date/month/year form?
Thanks,
Lois
--
View this message in context: http://r.789695.n4.nabble.com/Categorizing-by-month-tp4705173.html
Sent from the R help mailing list archive at Nabble.com.
</pre>lychang2015-03-27T16:06:36vif in package car: there are aliased coefficients in the model
http://comments.gmane.org/gmane.comp.lang.r.general/318851
<pre>Hello. I'm trying to use the function vif from package car in a lm. However
it returns the following error:
"Error in vif.default(lm(MDescores.sitescores ~ hidroperiodo + localizacao
+ : there are aliased coefficients in the model"
When I exclude any predictor from the model, it returns this warning
message:
"Warning message: In cov2cor(v) : diag(.) had 0 or NA entries; non-finite
result is doubtful"
When I exclude any other predictor from the model vif finally works. I
can't figure it out whats the problem. This are the results that R returns
me:
profundidade + NTVM + NTVI + PCs...c.1.., data = MDVIF))
Error in vif.default(lm(MDescores.sitescores ~ hidroperiodo + localizacao +
: there are aliased coefficients in the model
NTVI + PCs...c.1.., data = MDVIF))
GVIF Df GVIF^(1/(2*Df))
localizacao NaN 2 NaN
area NaN 1 NaN
profundidade NaN 1 NaN
NTVM NaN 1 NaN
NTVI NaN 1 NaN
PCs...c.1.. NaN 1 </pre>Rodolfo Pelinson2015-03-27T19:06:49Problem with download.file ?
http://comments.gmane.org/gmane.comp.lang.r.general/318847
<pre>
# download.file() Seems to put the xlsx file onto hard drive.
trying URL 'http://www.udel.edu/johnmack/data_library/zipcode_centroids.xlsx'
Content type 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' length 2785832 bytes (2.7 Mb)
opened URL
downloaded 2.7 Mb
# Trouble reading file with xlsx.
library(xlsx)
Loading required package: rJava
Loading required package: xlsxjars
Warning messages:
1: package ‘xlsx’ was built under R version 3.1.3
2: package ‘rJava’ was built under R version 3.1.3
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.util.zip.ZipException: invalid entry size (expected 1168 but got 1173 bytes)
# I downloaded the file manually (same name) from the web page and tried again.
# Then I read the file into R with xlsx successfully.
'data.frame':42961 obs. of 8 variables:
$ ZIPCODE : Factor w/ 42961 levels "01001","01002",..: 1 2 3 4 5 6 7 8 9 10 ...
$ TOWN. : Factor w/ 18955 levels "Aaronsburg","Abbeville",..: 85 33</pre>Giles Crane2015-03-27T14:25:56Calculating area of polygons created from a spatial intersect
http://comments.gmane.org/gmane.comp.lang.r.general/318846
<pre>-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all,
I am attempting to automate an analysis that I developed with ArcInfo
using R and the gdal and geos packages (or any other) if possible.
Here is the basic process
I have a shape file (lines) that defines the limits of all of the
projects with each project having a unique identifier.
I have another shape file (polys) that contains total population and
low income population and represent Census block groups. This shape
file has an area field which has the acreage of the total block group.
Process
Step 1.
I then buffer these project lines to create a second shape file that
represents the 'footprint' of the project. (Creates polys).
Step 2.
In ArcInfo, I perform an intersection of the two shape files
(footprint and census blocks) and this creates a third shape file
which has a unique polygon for every project/census block intersection.
Step 3.
I then perform an area calculation (acres) on this new poly shape file
and use this calculated area divi</pre>Walter Anderson2015-03-27T14:16:03matrix manipulation question
http://comments.gmane.org/gmane.comp.lang.r.general/318835
<pre>Hi,
I've got a rather large matrix of about 800 rows and 600000 columns.
Each column is a time-series 800 long.
Out of these 600000 time series, some have missing values (NA).
I want to strip out all columns that have one or more NA values, i.e.,
only want full time series.
This should do the trick:
data_no_NA <- data[,!apply(is.na(data), 2, any)]
I now use data_no_NA as input to a function, which returns output as a
matrix of the same size as data_no_NA
The trick is that i now need to put these columns back into a new 800 by
600000 empty matrix, at their original locations.
Any suggestions on how to do that? hopefully without having to use loops.
I'm using R/3.0.3
Cheers,
Jatin.
</pre>Jatin Kala2015-03-27T05:13:24Vennerable Plots for Publications
http://comments.gmane.org/gmane.comp.lang.r.general/318834
<pre>Does anyone make Venn diagrams for publication using Vennerable ? I found that the font size is too big when the plot is created at 300 DPI, and there's no option to change it, even when the point size argument to the device is changed.
aVenn <- Venn(Sets = list(A = 1:5, B = 3:6))
png("forPublication.png", units = "in", h = 2.55, w = 2.4, res = 300) # Changing pointsize to a smaller number has no effect on size of the text.
plot(aVenn)
dev.off()
--------------------------------------
Dario Strbenac
PhD Student
University of Sydney
Camperdown NSW 2050
Australia
</pre>Dario Strbenac2015-03-27T05:00:06basic help with as.Date()
http://comments.gmane.org/gmane.comp.lang.r.general/318829
<pre>Hi there: normally I’m quite comfortable with as.Date(). But this data set is causing problems.
The core of the data frame looks like the sample data frame below, but my attempt to convert df$mydate to a date object returns only NA. Can anyone provide a suggestion?
Thank you, Simon Kiss
#sample data frame
df<-data.frame(mydate=factor(c('Jan-15', 'Feb-13', 'Mar-11', 'Jul-12')), other=rnorm(4, 3))
#Attempt to convert
as.Date(as.character(df$mydate), format='%b-%y')
______________________________________________
R-help< at >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.</pre>Simon Kiss2015-03-26T21:11:50new package: canceR
http://comments.gmane.org/gmane.comp.lang.r.general/318828
<pre>Dear All,
I am pleased to announce the release of new package named canceR
<http://www.bioconductor.org/packages/devel/bioc/html/canceR.html>. The
main goal of this package is to facilitate to NOT R user the access of
complex cancer genomics data hosted by the MSKCC and available through
cgdsr CRAN package. By simple clic, the user can combine Cases (Samples)
and Genetic profiles to get rapidly without programming skills all
available cancer genomics data (CNA, mRNA, Methylation, Mutation, miRNA,
RPPA) in exportable table.
Compared to cBioportal <http://www.cbioportal.org/>, canceR allows user to
focus on some Studies and get specific data as Amino Acid changes in
Mutation Data for selected gene list.
The second part of canceR focus on modeling. I selected some interesting
fonctions from others packages (see Vignette) and I adapted them to
1-Associate phenotypes (gene / variable ) to disease
2-Classify genes by phenotype or disease
3-Enrichment gene expression data using GSEA-R (Broad Institute)
Other func</pre>Karim Mezhoud2015-03-26T19:49:54list output
http://comments.gmane.org/gmane.comp.lang.r.general/318824
<pre>Hello!
I am having some trouble with some list output.
Here is my code:
geobunch <- function(y) {
out <- vector("list",3)
aic <- numeric(length=3)
print(str(out))
for(i in 1:3) {
x <- geomin(y,i)
print(i)
print(x)
print(str(x))
out[i]$phi_0 <- x$phi_0
out[i]$maxlike <- x$maxlike
out[i]$bigp <- x$bigp
aic[i] <- -2*out[i]$maxlike + (2*(i+1))
}
minaic <- which(aic==min(aic))
minout <- out[unlist(minaic)]
return(minout)
}
And here is the output:
List of 3
$ : NULL
$ : NULL
$ : NULL
NULL
[1] 1
$phi_0
[1] 2.856428
$bigp
[1] 0.1584016
$maxlike
[1] -473.0203
List of 3
$ phi_0 : num 2.86
$ bigp : num 0.158
$ maxlike: num -473
NULL
Error in aic[i] <- -2 * out[i]$maxlike + (2 * (i + 1)) :
replacement has length zero
In addition: Warning messages:
1: In out[i]$phi_0 <- x$phi_0 :
number of items to replace is not a multiple of replacement length
2: In o</pre>Erin Hodgess2015-03-26T18:22:14y axis in a stacked bar plot
http://comments.gmane.org/gmane.comp.lang.r.general/318817
<pre>Hello,
Below is some simple R code I have used to create a stacked bar chart. However the y-axis tick marks do not reflect the data. The minimum and maximum data values I have are 3073351 and 25329814 respectively but the graph has data from 0 and the maximum is different The data file is too large so there is a small sample below. What am I doing wrong? Please help as I cannot be sure the data is represented correctly in the graph (attached).
fn <-"~/Documents/chr7Data.txt"
x<-read.table(fn,check.names = TRUE, header=T)
d <- data.frame(x)
theChart<-ggplot(d, aes(x=factor(Congenic),y=Position, fill=Strain, theme_rect="white")) + geom_bar(stat='identity', position = "stack" ) + scale_fill_manual(values=c("deepskyblue1", "red2", "green3", "steelblue4", "lightblue4", "gray70")) + ylab(c("Position"))+
ggtitle("Strain specific SNP distribution in the congenics") +
#coord_cartesian(ylim = c(min(d$Position), max(d$Position))) +
#scale_y_continuous(breaks=seq(0, 200000000, 50000000)) +
theme_bw()+
theme(plot.</pre>Michelle Simon2015-03-26T04:29:40Having trouble with gdata read in
http://comments.gmane.org/gmane.comp.lang.r.general/318813
<pre>Trying to read and clean up the FERC data on Advanced Metering infrastructure. Of course it is in XLS for the first two survey years and then converts to XLSX for the final two. Bad enough that it is all in excel, they had to change the survey design and data format as well. Still, I’m sorting through it. However, when I try and read in the 2008 data, I’m getting this error:
###
Wide character in print at /Library/Frameworks/R.framework/Versions/3.1/Resources/library/gdata/perl/xls2csv.pl line 270.
Warning message:
In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
EOF within quoted string
###
Here is the code I’m running to get the data:
###
install.packages("gdata")
library("gdata")
fileUrl <- "http://www.ferc.gov/industries/electric/indus-act/demand-response/2008/survey/ami_survey_responses.xls"
download.file(fileUrl, destfile="./ami.data/ami-data2008.xls")
list.files("ami.data")
dateDown.2008 <- date()
ami.data2008 <- read.xls("./ami.data/ami-data2008.xls", sheet=1, head</pre>Benjamin Baker2015-03-25T21:01:49including internal data in a package
http://comments.gmane.org/gmane.comp.lang.r.general/318812
<pre>CRAN check is issuing a complaint,
Found the following calls to data() loading into the global environment:
File ‘OpenMx/R/MxAlgebra.R’:
data(omxSymbolTable)
See section ‘Good practice’ in ‘?data’.
I tried placing an rda file in the package's R/ directory, but now I get
a new CRAN check complaint,
Subdirectory 'R' contains invalid file names:
‘omxSymbolTable.rda’
Furthermore, I can't figure out how to load this file. I found this 2013
post,
http://r.789695.n4.nabble.com/Good-practice-for-data-for-R-packages-td4660313.html
"The objects will be available in your NAMESPACE." -- I don't
understand. Can somebody clarify?
Thanks.
</pre>Joshua N Pritikin2015-03-25T20:15:00print and rbind within a for loop
http://comments.gmane.org/gmane.comp.lang.r.general/318807
<pre>Greets,
I'm trying to iteratively find solutions to a problem given a range of options. Code is as follows:
sim.app.wald<-function(B=0.1,min=10,max=50,alpha=0.05){
result<-c(fails=0,n=0)
for(n in min:max){
x<-seq(1,n-1,1)
fhat<-x/n
se<-sqrt((fhat*(1-fhat))/n)
ci.wald<-fhat+qnorm(1-(alpha/2))*se
if(sum(ci.wald[ci.wald<=B])){
#rbind(cbind(fails=x[ci.wald<=B],n=n),result)
print(cbind(X=x[ci.wald<=B],n))
}
#return(result)
}
}
If you run it like this, you can readily see what I intend to get out; which is the correct result. If you uncomment the two commented lines, nothing useful obtains.
What am I missing here? This seeming codependence of print() and return() and the failure of rbind() to do anything is quite puzzling.
Best Regards,
Steven
[[alternative HTML version deleted]]
</pre>Steven LeBlanc2015-03-25T19:43:08Converting charter string to vector of numbers
http://comments.gmane.org/gmane.comp.lang.r.general/318805
<pre>Apologies for bringing up an old topic, but I am not finding working answers.
I am also an R newbie, so I'm still on the steep part of the learning curve.
I have a character string : "0.5 1 2 3 4"
I need to convert it to a vector of numbers. I get as far as strsplit(),
which gives me
"0.5" "1" "2" "3" "4"
this is still treated by R as a single item. I need to get it to look like
this: "0.5", "1", "2", "3", "4"
so that I can use as.numeric() and make it into a vector of numbers... I
have been going mad because for text operations, commas and quotes are
loaded with meaning, and I keep going around in circles.
Any help would be appreciated
Thanks
Paul
--
View this message in context: http://r.789695.n4.nabble.com/Converting-charter-string-to-vector-of-numbers-tp4705097.html
Sent from the R help mailing list archive at Nabble.com.
</pre>Turgidson2015-03-25T17:27:40Resizing a graph with a legend in the outer margin - wish for functionality like mtext()
http://comments.gmane.org/gmane.comp.lang.r.general/318803
<pre>Dear R-Helpers
I am attempting to get a legend in the outer margins of a graph that has a
similar flexibility to mtext(), within base graphics. This is used in a
tool that will end up with graphs of many different coordinates, exported
in many different sizes. I'm trying to come up with a general solution.
I've used "bottom right" before but I found it interferes with the graphs
frequently.
Here was my best attempt at something general, but then I encountered the
graph re-sizing issue:
x <- 1:100
y <- x +rnorm(100, 0,10)
plot(x,y, xlab="", main="Shrink and Enlarge This Graph")
abline(0,1 ,lty=2)
legend(x=grconvertX(1, from = "ndc", to = "user"),
y=grconvertY(0, from = "ndc", to = "user"),
lty=2,
legend="The legend doesn't rescale nicely",
xjust=1, yjust=0,
bty="n",
xpd=TRUE)
mtext("This example has some text in the outer margin.\nIt rescales
nicely.",
side = 1, line=3.5, adj=0)
Thanks!
Peter
[[alternative HTML version deleted]]
</pre>Peter Lomas2015-03-25T18:21:49Search EngineSearch the mailing list at Gmanequery
http://search.gmane.org/?group=$group=gmane.comp.lang.r.general