Re: [R] factor() in lm

2013-12-01 Thread Gary Dong
o > trouble. But if this is newish behavior and you are using an oldish > version, you might try upgrading to the current version. Or (more > likely) both clauses of this conditional are false and should be > ignored, and I should preemptively apologize for my foolishness. > > Che

[R] factor() in lm

2013-12-01 Thread Gary Dong
Dear R users, I am running a linear regression in R. My observations are Census Tracts in several metropolitan areas (MSAs). In my data set, each MSA has at least 50 observations. I use factor(msa_code) in the lm formula to control for metropolitan fixed effects. But I kept getting something like

[R] summary many regressions

2013-11-25 Thread Gary Dong
Dear R users, I have a large data set which includes data from 300 cities. I want to run a biviriate regression for each city and record the coefficient and the adjusted R square. For example, in the following, I have 10 cities represented by numbers from 1 to 10: x = cumsum(c(0, runif(999, -1,

[R] if else in R

2013-11-19 Thread Gary Dong
Dear R users, I am a R beginner and I am having trouble in using "If Else" in R. Here is an example: ## create a data frame a<-c(1,2,3,4) b<-c(2,0,5,0) ab<-data.frame(cbind(a,b)) ##calculate c, which is the ratio between a and b if(ab$b>0) { ab$c<-ab$a/ab$b } else { ab$c<-0 } here is the e

[R] plot time series data in wide format

2013-11-01 Thread Gary Dong
Dear R users, I wonder if there is a way that I can plot a time series data which is in a wide format like this: CITY_NAME 2000Q12000Q2 2000Q32000Q4 2001Q1 2001Q2 2001Q3 2001Q4 2002Q1 2002Q2 CITY1100.5210 101.9667 103.24933 104.050

[R] extraction of roots in R

2013-11-01 Thread Gary Dong
Dear R users, I wonder if R has a default function that I can use to do extraction of roots. Here is an example: X N 2.5 5 3.4 7 8.9 9 6.4 1 2.1 0 1.1 2 I want to calculate Y = root(X)^N, where N repre

[R] find max value in each row and return column number and column name

2013-11-01 Thread Gary Dong
Dear R users, I wonder how I can use R to identify the max value of each row, the column number column name: For example: a <- data.frame(x = rnorm(4), y = rnorm(4), z = rnorm(4)) > a x y z 1 -0.7289964 0.2194702 -2.4674780 2 1.0889353 0.3167629 -0.9208548 3 -0.6

[R] Interpretation of coefficients in spatial lag models

2013-10-07 Thread Gary Dong
Dear R users, I have estimated a spatial lag model using the "spdep" package. I understand that to interpret the magnitude of coefficients correctly, I have to use impact() to calculate the direct and indirect impacts. Here are the estimation results for a variable X, which is statistically signi

[R] Logged ratio as Dependent variable

2013-09-12 Thread Gary Dong
Dear R users, I have a question regarding using logged ratio as dependent variable in regression. I am reading a paper discussing how a waste management facility has influenced housing price in surrounding areas. The author used Ln(P2/P1) as the dependent variable, where P1 and P2 represent trade

[R] Error in x[[1]] : subscript out of bounds

2013-05-31 Thread Gary Dong
Dear R users, I am estimating a nested logit model using "mlogit", but keep getting this error message: "Error in x[[1]] : subscript out of bounds" Anyone can tell me what this error means? Simple MNL model worked with the same data. Thank you! Gary [[alternative HTML version deleted

Re: [R] write table in ascii

2013-05-30 Thread Gary Dong
Thu, May 30, 2013 at 6:35 PM, Gary Dong wrote: > > Dear R users, > > > > I have a data set in .csv and I hope to convert it to .dat (ascii) so it > > can work in an UNIX environment. Anyone can help me? Thank you! > > Please expand. Why can't you work with csv

[R] write table in ascii

2013-05-30 Thread Gary Dong
Dear R users, I have a data set in .csv and I hope to convert it to .dat (ascii) so it can work in an UNIX environment. Anyone can help me? Thank you! Gary [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.

Re: [R] Mlogit error

2013-05-30 Thread Gary Dong
Hi, Graham, Thank you for sharing this. I encountered the same problem. My choice set was unbalanced because some alternatives were not available for some observations. If I forced the choice sets balanced, model estimation results would be biased. However, after including chid.var = "" and alt.va

[R] "mlogit" does not report number of observation?

2013-05-30 Thread Gary Dong
Dear R users, I am wondering if there is an easy way to have "mlogit" to report number of observations (N) used in the model. It seems "summary()" does not work. Thank you! Gary [[alternative HTML version deleted]] __ R-help@r-project.org mail

[R] Warning: Spatial weights matrix not row standardized

2013-01-29 Thread Gary Dong
Hi, R users, I am doing Lagrange Multiplier Test Statistics for Spatial Autocorrelation with "spdep" and got this warning message: "Spatial weights matrix not row standardized". It is a warning, not an error. I am wondering if this is a problem. Thanks! Gary [[alternative HTML version

[R] cannot print neighbor list object

2013-01-29 Thread Gary Dong
Hi, R users, I am estimating a spatial lag model using the "spdep" package. Before running the model, I was creating K nearest neighbours for spatial weights. My observations are points. Let me use the "coords" in Columbus dataset as an example, and I consider 5 nearest neighbors. library(spdep)

[R] Multi lines in R plot

2012-09-19 Thread Gary Dong
Dear R users, I'm plotting 5 loess smooth lines in one paragraph. Since the publisher does not print colorful pictures, I differentiate them by using different line types. I'm wondering if there are other options to make the graph more readable. It is really difficult for readers to tell the diffe

[R] Pseudo R squared in gls model

2012-08-23 Thread Gary Dong
Dear R users, I'm wondering if the gls function reports pseudo R. I do not see it by summary(). If the package does not report, can I calculate it in this way? Adjusted pseudo R squared = 1 - [(Loglik(beta) - k ) / Loglik(null)] where k is the number of IVs. Thanks! Gary [[alternative

[R] negative AIC and BIC values in gls

2012-08-22 Thread Gary Dong
Dear R users, I obtained negative AIC and BIC and positive Loglik values in a gls model. Is this normal? how should I interpret them? Thanks! AIC BIC logLik -659.978 -587.5541 345.989 Best Gary [[alternative HTML version deleted]] ___

[R] spatial auto-correlation structure in nlme

2012-08-17 Thread Gary Dong
Dear R users, I'm estimating a mixed effects model in which the spatial correlation is controlled for by the "corGaus" structure. I'm wondering if there is a document or paper that explains how the spatial correlation structure (such as "corExp" or "corGaus") works. Let me use the example and dat

[R] memory size

2012-07-21 Thread Gary Dong
Dear R community, I'm running "a mlogit" function with a very large data set. Since the data size is so large, I got the Error: Error: cannot allocate vector of size 5.4 Mb In addition: Warning messages: 1: In mapply("*", X, P, SIMPLIFY = FALSE) : Reached total allocation of 16340Mb: see help(m

[R] 3-d kernel smooth by the "kde" function

2012-07-18 Thread Gary Dong
Dear R community, I'm having hard time to understand the kde function in "ks" package. Let me use a 3-dimensional kernel smooth example to explain my question using the elevation data in geoR. ### here is what I did ### library(ks) require(geoR) data(elevation) elev.df <- data.frame(x = elevatio

Re: [R] plotting points to a map

2012-07-18 Thread Gary Dong
lat, I mean distances to the city center from south-north and east-west directions. 2) I know the coordinate of the reference point. Thanks. Best Gary On Wed, Jul 18, 2012 at 11:30 AM, Sarah Goslee wrote: > Hi, > > On Wed, Jul 18, 2012 at 2:11 PM, Gary Dong wrote: > > Dear R u

[R] plotting points to a map

2012-07-18 Thread Gary Dong
Dear R users, I have a city map in shape file (polygon). I also have some points that I hope to plot them to the city map. The only information I have about those points are their relative longitude and latitude to the city center by miles. Is there a way that R can help me to do this? Thanks. Ga

[R] Kernel smoothing ("ks" package)

2012-07-17 Thread Gary Dong
Dear R users, I'm trying to determine local population centers in a region through kernel smoothing. What I have is population density in each neighborhood, which can be presented as point density. So in my data set “pop”, I have three columns for about 1000 neighborhoods: x (x coordinate), y (y c

Re: [R] identifying local maxima

2012-07-16 Thread Gary Dong
local maxima. Thanks. Gary On Thu, Jul 12, 2012 at 5:26 AM, Hans W Borchers wrote: > Gary Dong gmail.com> writes: > > > > Dear R users, > > > > I have created a Loess surface in R, in which x is relative longitude by > > miles, y is relative latitude by mi

[R] identifying local maxima

2012-07-11 Thread Gary Dong
Dear R users, I have created a Loess surface in R, in which x is relative longitude by miles, y is relative latitude by miles, and z is population density at the neighborhood level. The purpose is to identify some population centers in the region. I'm wondering if there is a way to determine the c

[R] calculating inflection point in mixed effect model

2012-06-21 Thread Gary Dong
Hi, dear R users, I estimated a mixed-effects model with the lme function in R. In this model, the relationship between my predictor x and the DV y follows quadratic function. In other words, in the model, x has a positive coefficient while x squared has a negative coefficient. I'm wondering how I

Re: [R] Multi-threads in R

2012-06-17 Thread Gary Dong
hael > > On Jun 17, 2012, at 11:39 AM, Gary Dong wrote: > > > Dear R users, > > > > I'm wonder if there is a easy way to make R use multi-CPUs on my > computer. > > My computer has four CPUs but R uses only one. Thanks.

[R] Multi-threads in R

2012-06-17 Thread Gary Dong
Dear R users, I'm wonder if there is a easy way to make R use multi-CPUs on my computer. My computer has four CPUs but R uses only one. Thanks. Gary [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch

[R] Specifying spatial correlation Form in nmle

2012-06-12 Thread Gary Dong
Dear R users, I'm applying a correlation structure in a mixed model (nmle function) to control for spatial correlation between land parcels that are adjacent to each other. I generated X,Y coordinates in ArcGIS for each land parcel and used them in the correlation form like this: test.exp<-corExp

Re: [R] controlling spatial autocorrelation in linear regression models

2012-06-11 Thread Gary Dong
Thanks! This link is very helpful. Best Gary On Mon, Jun 11, 2012 at 4:28 AM, D.Soudis wrote: > > Hi, > > Maybe this is helpful..?? > > http://www.ats.ucla.edu/stat/r/faq/spatial_regression.htm > > Best, > Dimitrios > > -- > View this message in context: > http://r.789695.n4.nabble.com/controll

[R] controlling spatial autocorrelation in linear regression models

2012-06-10 Thread Gary Dong
Dear R users, I'm estimating a hedonic land price model at the parcel level, basically a linear regression model with land price as the dependent variable. I'm wondering if there is a function in R that I can use to control spatial auto-correlation among parcels that are adjacent to each other. I

[R] lmer function in R

2012-06-09 Thread Gary Dong
Dear R users, I'm estimating a two-level regresion model but having difficuly in finding a good R syntax example. Let me use an example to explain what I'm doing. The dependent variable is math score (mathscore). Predictors are at two levels. At the student level, they are household income (hinc)

Re: [R] Two Y axes (same scale) in ggplot2 or plot

2012-05-09 Thread Gary Dong
Thanks, Duncan. I tried axis(). It appears it allows you to add an axis, but does not say you can plot a second Y in the graph. Maybe I'm understanding it correctly. Any help will be appreciated! Gary On Wed, May 9, 2012 at 7:26 AM, Duncan Murdoch wrote: > On 08/05/2012 3:23 PM, G

[R] Two Y axes (same scale) in ggplot2 or plot

2012-05-08 Thread Gary Dong
Dear R users, I'm plotting housing prices in City A over past 30 years in ggplot2. The Xs are years since 1980. I have two housing price variables: new home prices and old home prices, both of them measured by $/sqft. I have searched related threads on multiple Y axes in ggplot2 and I understand t

[R] two Y Axes (in the same scale) in ggplot2

2012-05-08 Thread Gary Dong
Dear R users, I'm plotting housing prices in City A over past 30 years in ggplot2. The Xs are years since 1980. I have two housing price variables: new home prices and old home prices, both of them measured by $/sqft. I have searched related threads on multiple Y axes in ggplot2 and I understand t