Intrucciones generales:
turdus1 <- turdus[grep("song", turdus$Vocalization_type), ]
R/ Usando el argumento ‘ignore.case’.
turdus1 <- turdus[grep("song", turdus$Vocalization_type, ignore.case = TRUE),]
##### Con for loop
dist_lat <- function(X) {
res <- list()
for(z in unique(X$Specific_epithet))
{
sp.dt <- X[X$Specific_epithet == z, ]
lim.Sur <- min(sp.dt$Latitude, na.rm = TRUE)
lim.Norte <- max(sp.dt$Latitude, na.rm = TRUE)
rango <- (lim.Norte - lim.Sur)
punto.medio <- lim.Norte - (rango/2)
df <- data.frame(especie = z, lim.Norte, lim.Sur, punto.medio)
res[[length(res) + 1]] <- df
}
res2 <- do.call(rbind, res)
return(res2)
}
# hacer lat numerico
turdus$Latitude <- as.numeric(as.character(turdus$Latitude))
dist_lat(turdus)
## especie lim.Norte lim.Sur punto.medio
## 1 litsitsirupa 14.248900 -29.047600 -7.399350
## 2 flavipes 11.270000 -29.613400 -9.171700
## 3 leucops 9.604800 -16.250100 -3.322650
## 4 pelios 13.639600 -12.085226 0.777187
## 5 tephronotus 4.714186 -4.090400 0.311893
## 6 libonyana -6.027000 -31.005100 -18.516050
## 7 olivaceofuscus 0.288500 0.112100 0.200300
## 8 xanthorhynchus 1.551600 1.551600 1.551600
## 9 olivaceus -23.033000 -34.389200 -28.711100
## 10 roehli -4.727300 -5.101200 -4.914250
## 11 abyssinicus 12.028000 -7.880500 2.073750
## 12 smithi -25.767100 -32.287600 -29.027350
## 13 helleri -3.369200 -3.369200 -3.369200
## 14 menachensis 18.965400 18.226400 18.595900
## 15 bewsheri -12.225000 -12.372200 -12.298600
## 16 hortulorum 49.869900 30.206000 40.037950
## 17 unicolor 37.486700 21.583400 29.535050
## 18 dissimilis 26.872000 19.911400 23.391700
## 19 cardis 43.358800 18.758600 31.058700
## 20 albocinctus 30.477600 27.282800 28.880200
## 21 torquatus 69.776300 36.697600 53.236950
## 22 boulboul 34.646060 26.928400 30.787230
## 23 merula 69.585000 -46.895900 11.344550
## 24 mandarinus 39.075000 29.307600 34.191300
## 25 maximus 34.646060 29.429000 32.037530
## 26 simillimus 21.114000 6.800000 13.957000
## 27 poliocephalus 24.300000 -18.052000 3.124000
## 28 rubrocanus 37.038160 18.588800 27.813480
## 29 kessleri 36.916200 30.896700 33.906450
## 30 feae 40.819500 18.586100 29.702800
## 31 obscurus 63.166100 -1.734200 30.715950
## 32 pallidus 49.438100 25.014500 37.226300
## 33 chrysolaus 46.971000 22.518400 34.744700
## 34 celaenops 34.055300 33.096144 33.575722
## 35 atrogularis 66.686000 27.320168 47.003084
## 36 ruficollis 63.484600 27.757800 45.621200
## 37 naumanni 62.068000 34.688900 48.378450
## 38 eunomus 64.807800 33.230800 49.019300
## 39 pilaris 70.375300 36.028800 53.202050
## 40 iliacus 70.527400 37.397900 53.962650
## 41 philomelos 70.124100 -46.897000 11.613550
## 42 mupinensis 40.587800 29.850600 35.219200
## 43 viscivorus 68.997300 29.446900 49.222100
## 44 fuscater 11.123700 -16.904000 -2.890150
## 45 chiguanco -1.733000 -44.800400 -23.266700
## 46 nigrescens 10.160000 8.803600 9.481800
## 47 infuscatus 19.661600 13.902900 16.782250
## 48 serranus 10.417000 -22.188333 -5.885667
## 49 nigriceps -3.229500 -27.866700 -15.548100
## 50 subalaris -12.583400 -34.283300 -23.433350
## 51 reevei -3.650000 -6.301400 -4.975700
## 52 olivater 11.200000 1.668200 6.434100
## 53 maranonicus -4.550000 -6.833333 -5.691667
## 54 fulviventris 8.616400 -5.316700 1.649850
## 55 rufiventris -4.229800 -38.987900 -21.608850
## 56 falcklandii -32.466700 -54.844800 -43.655750
## 57 leucomelas 11.269800 -31.718400 -10.224300
## 58 amaurochalinus -6.088700 -39.677200 -22.882950
## 59 plebejus 16.758000 8.497000 12.627500
## 60 ignobilis 10.303300 -12.866000 -1.281350
## 61 lawrencii 1.259800 -14.567000 -6.653600
## 62 fumigatus 10.713700 -16.452500 -2.869400
## 63 obsoletus 9.644800 -3.898300 2.873250
## 64 hauxwelli 3.862700 -17.783300 -6.960300
## 65 haplochrous -14.209000 -14.748900 -14.478950
## 66 grayi 27.044600 3.831300 15.437950
## 67 nudigenis 14.089200 -6.602100 3.743550
## 68 sanchezorum 0.005500 -7.216700 -3.605600
## 69 maculirostris 0.850000 -4.437300 -1.793650
## 70 jamaicensis 18.082900 18.082900 18.082900
## 71 assimilis 28.373000 7.609400 17.991200
## 72 daguae 7.843656 -0.052300 3.895678
## 73 albicollis 10.713700 -35.250100 -12.268200
## 74 rufopalliatus 33.932900 17.067000 25.499950
## 75 rufitorques 16.800000 13.940500 15.370250
## 76 migratorius 64.862600 16.144500 40.503550
## 77 swalesi 18.561646 18.242000 18.401823
## 78 aurantius 18.167872 18.047400 18.107636
## 79 plumbeus 26.506500 18.157100 22.331800
## 80 lherminieri 16.310800 15.370900 15.840850
## 81 eremita -37.086900 -37.423800 -37.255350
##### Con lapply
dist_lat <- function(X) {
res <- lapply(unique(X$Specific_epithet), function(z)
{
sp.dt <- X[X$Specific_epithet == z, ]
lim.Sur <- min(sp.dt$Latitude, na.rm = TRUE)
lim.Norte <- max(sp.dt$Latitude, na.rm = TRUE)
rango <- (lim.Norte - lim.Sur)
punto.medio <- lim.Norte - (rango/2)
df <- data.frame(especie = z, lim.Norte, lim.Sur, punto.medio)
})
res2 <- do.call(rbind, res)
return(res2)
}
dist_lat(turdus)
## especie lim.Norte lim.Sur punto.medio
## 1 litsitsirupa 14.248900 -29.047600 -7.399350
## 2 flavipes 11.270000 -29.613400 -9.171700
## 3 leucops 9.604800 -16.250100 -3.322650
## 4 pelios 13.639600 -12.085226 0.777187
## 5 tephronotus 4.714186 -4.090400 0.311893
## 6 libonyana -6.027000 -31.005100 -18.516050
## 7 olivaceofuscus 0.288500 0.112100 0.200300
## 8 xanthorhynchus 1.551600 1.551600 1.551600
## 9 olivaceus -23.033000 -34.389200 -28.711100
## 10 roehli -4.727300 -5.101200 -4.914250
## 11 abyssinicus 12.028000 -7.880500 2.073750
## 12 smithi -25.767100 -32.287600 -29.027350
## 13 helleri -3.369200 -3.369200 -3.369200
## 14 menachensis 18.965400 18.226400 18.595900
## 15 bewsheri -12.225000 -12.372200 -12.298600
## 16 hortulorum 49.869900 30.206000 40.037950
## 17 unicolor 37.486700 21.583400 29.535050
## 18 dissimilis 26.872000 19.911400 23.391700
## 19 cardis 43.358800 18.758600 31.058700
## 20 albocinctus 30.477600 27.282800 28.880200
## 21 torquatus 69.776300 36.697600 53.236950
## 22 boulboul 34.646060 26.928400 30.787230
## 23 merula 69.585000 -46.895900 11.344550
## 24 mandarinus 39.075000 29.307600 34.191300
## 25 maximus 34.646060 29.429000 32.037530
## 26 simillimus 21.114000 6.800000 13.957000
## 27 poliocephalus 24.300000 -18.052000 3.124000
## 28 rubrocanus 37.038160 18.588800 27.813480
## 29 kessleri 36.916200 30.896700 33.906450
## 30 feae 40.819500 18.586100 29.702800
## 31 obscurus 63.166100 -1.734200 30.715950
## 32 pallidus 49.438100 25.014500 37.226300
## 33 chrysolaus 46.971000 22.518400 34.744700
## 34 celaenops 34.055300 33.096144 33.575722
## 35 atrogularis 66.686000 27.320168 47.003084
## 36 ruficollis 63.484600 27.757800 45.621200
## 37 naumanni 62.068000 34.688900 48.378450
## 38 eunomus 64.807800 33.230800 49.019300
## 39 pilaris 70.375300 36.028800 53.202050
## 40 iliacus 70.527400 37.397900 53.962650
## 41 philomelos 70.124100 -46.897000 11.613550
## 42 mupinensis 40.587800 29.850600 35.219200
## 43 viscivorus 68.997300 29.446900 49.222100
## 44 fuscater 11.123700 -16.904000 -2.890150
## 45 chiguanco -1.733000 -44.800400 -23.266700
## 46 nigrescens 10.160000 8.803600 9.481800
## 47 infuscatus 19.661600 13.902900 16.782250
## 48 serranus 10.417000 -22.188333 -5.885667
## 49 nigriceps -3.229500 -27.866700 -15.548100
## 50 subalaris -12.583400 -34.283300 -23.433350
## 51 reevei -3.650000 -6.301400 -4.975700
## 52 olivater 11.200000 1.668200 6.434100
## 53 maranonicus -4.550000 -6.833333 -5.691667
## 54 fulviventris 8.616400 -5.316700 1.649850
## 55 rufiventris -4.229800 -38.987900 -21.608850
## 56 falcklandii -32.466700 -54.844800 -43.655750
## 57 leucomelas 11.269800 -31.718400 -10.224300
## 58 amaurochalinus -6.088700 -39.677200 -22.882950
## 59 plebejus 16.758000 8.497000 12.627500
## 60 ignobilis 10.303300 -12.866000 -1.281350
## 61 lawrencii 1.259800 -14.567000 -6.653600
## 62 fumigatus 10.713700 -16.452500 -2.869400
## 63 obsoletus 9.644800 -3.898300 2.873250
## 64 hauxwelli 3.862700 -17.783300 -6.960300
## 65 haplochrous -14.209000 -14.748900 -14.478950
## 66 grayi 27.044600 3.831300 15.437950
## 67 nudigenis 14.089200 -6.602100 3.743550
## 68 sanchezorum 0.005500 -7.216700 -3.605600
## 69 maculirostris 0.850000 -4.437300 -1.793650
## 70 jamaicensis 18.082900 18.082900 18.082900
## 71 assimilis 28.373000 7.609400 17.991200
## 72 daguae 7.843656 -0.052300 3.895678
## 73 albicollis 10.713700 -35.250100 -12.268200
## 74 rufopalliatus 33.932900 17.067000 25.499950
## 75 rufitorques 16.800000 13.940500 15.370250
## 76 migratorius 64.862600 16.144500 40.503550
## 77 swalesi 18.561646 18.242000 18.401823
## 78 aurantius 18.167872 18.047400 18.107636
## 79 plumbeus 26.506500 18.157100 22.331800
## 80 lherminieri 16.310800 15.370900 15.840850
## 81 eremita -37.086900 -37.423800 -37.255350
Pistas:
dist_lat2 <- function(X) {
# graficar un histograma por especie
res <- lapply(unique(X$Specific_epithet), function(z)
{
sp.dt <- X[X$Specific_epithet == z, ]
lim.Sur <- min(sp.dt$Latitude, na.rm = TRUE)
lim.Norte <- max(sp.dt$Latitude, na.rm = TRUE)
punto.medio <- mean(c(lim.Norte, lim.Sur))
lon <- sp.dt$Longitude[!is.na(sp.dt$Longitude)]
if(all(lon < -25)) mundo <- "Nuevo Mundo"
if(all(lon > -25)) mundo <- "Viejo Mundo"
if(any(lon > -25) & any(lon < -25)) mundo <- "Ambos"
df <- data.frame(especie = z, lim.Norte, lim.Sur, punto.medio, mundo)
})
df <- do.call(rbind, res)
return(df)
}
# hacer lon numerico
turdus$Longitude <- as.numeric(as.character(turdus$Longitude))
dist_lat2(turdus)
## especie lim.Norte lim.Sur punto.medio mundo
## 1 litsitsirupa 14.248900 -29.047600 -7.399350 Viejo Mundo
## 2 flavipes 11.270000 -29.613400 -9.171700 Nuevo Mundo
## 3 leucops 9.604800 -16.250100 -3.322650 Nuevo Mundo
## 4 pelios 13.639600 -12.085226 0.777187 Viejo Mundo
## 5 tephronotus 4.714186 -4.090400 0.311893 Viejo Mundo
## 6 libonyana -6.027000 -31.005100 -18.516050 Viejo Mundo
## 7 olivaceofuscus 0.288500 0.112100 0.200300 Viejo Mundo
## 8 xanthorhynchus 1.551600 1.551600 1.551600 Viejo Mundo
## 9 olivaceus -23.033000 -34.389200 -28.711100 Viejo Mundo
## 10 roehli -4.727300 -5.101200 -4.914250 Viejo Mundo
## 11 abyssinicus 12.028000 -7.880500 2.073750 Viejo Mundo
## 12 smithi -25.767100 -32.287600 -29.027350 Viejo Mundo
## 13 helleri -3.369200 -3.369200 -3.369200 Viejo Mundo
## 14 menachensis 18.965400 18.226400 18.595900 Viejo Mundo
## 15 bewsheri -12.225000 -12.372200 -12.298600 Viejo Mundo
## 16 hortulorum 49.869900 30.206000 40.037950 Viejo Mundo
## 17 unicolor 37.486700 21.583400 29.535050 Viejo Mundo
## 18 dissimilis 26.872000 19.911400 23.391700 Viejo Mundo
## 19 cardis 43.358800 18.758600 31.058700 Viejo Mundo
## 20 albocinctus 30.477600 27.282800 28.880200 Viejo Mundo
## 21 torquatus 69.776300 36.697600 53.236950 Viejo Mundo
## 22 boulboul 34.646060 26.928400 30.787230 Viejo Mundo
## 23 merula 69.585000 -46.895900 11.344550 Ambos
## 24 mandarinus 39.075000 29.307600 34.191300 Viejo Mundo
## 25 maximus 34.646060 29.429000 32.037530 Viejo Mundo
## 26 simillimus 21.114000 6.800000 13.957000 Viejo Mundo
## 27 poliocephalus 24.300000 -18.052000 3.124000 Ambos
## 28 rubrocanus 37.038160 18.588800 27.813480 Viejo Mundo
## 29 kessleri 36.916200 30.896700 33.906450 Viejo Mundo
## 30 feae 40.819500 18.586100 29.702800 Viejo Mundo
## 31 obscurus 63.166100 -1.734200 30.715950 Viejo Mundo
## 32 pallidus 49.438100 25.014500 37.226300 Viejo Mundo
## 33 chrysolaus 46.971000 22.518400 34.744700 Viejo Mundo
## 34 celaenops 34.055300 33.096144 33.575722 Viejo Mundo
## 35 atrogularis 66.686000 27.320168 47.003084 Viejo Mundo
## 36 ruficollis 63.484600 27.757800 45.621200 Viejo Mundo
## 37 naumanni 62.068000 34.688900 48.378450 Viejo Mundo
## 38 eunomus 64.807800 33.230800 49.019300 Viejo Mundo
## 39 pilaris 70.375300 36.028800 53.202050 Viejo Mundo
## 40 iliacus 70.527400 37.397900 53.962650 Ambos
## 41 philomelos 70.124100 -46.897000 11.613550 Ambos
## 42 mupinensis 40.587800 29.850600 35.219200 Viejo Mundo
## 43 viscivorus 68.997300 29.446900 49.222100 Viejo Mundo
## 44 fuscater 11.123700 -16.904000 -2.890150 Nuevo Mundo
## 45 chiguanco -1.733000 -44.800400 -23.266700 Nuevo Mundo
## 46 nigrescens 10.160000 8.803600 9.481800 Nuevo Mundo
## 47 infuscatus 19.661600 13.902900 16.782250 Nuevo Mundo
## 48 serranus 10.417000 -22.188333 -5.885667 Nuevo Mundo
## 49 nigriceps -3.229500 -27.866700 -15.548100 Nuevo Mundo
## 50 subalaris -12.583400 -34.283300 -23.433350 Nuevo Mundo
## 51 reevei -3.650000 -6.301400 -4.975700 Nuevo Mundo
## 52 olivater 11.200000 1.668200 6.434100 Nuevo Mundo
## 53 maranonicus -4.550000 -6.833333 -5.691667 Nuevo Mundo
## 54 fulviventris 8.616400 -5.316700 1.649850 Nuevo Mundo
## 55 rufiventris -4.229800 -38.987900 -21.608850 Nuevo Mundo
## 56 falcklandii -32.466700 -54.844800 -43.655750 Nuevo Mundo
## 57 leucomelas 11.269800 -31.718400 -10.224300 Nuevo Mundo
## 58 amaurochalinus -6.088700 -39.677200 -22.882950 Nuevo Mundo
## 59 plebejus 16.758000 8.497000 12.627500 Nuevo Mundo
## 60 ignobilis 10.303300 -12.866000 -1.281350 Nuevo Mundo
## 61 lawrencii 1.259800 -14.567000 -6.653600 Nuevo Mundo
## 62 fumigatus 10.713700 -16.452500 -2.869400 Nuevo Mundo
## 63 obsoletus 9.644800 -3.898300 2.873250 Nuevo Mundo
## 64 hauxwelli 3.862700 -17.783300 -6.960300 Nuevo Mundo
## 65 haplochrous -14.209000 -14.748900 -14.478950 Nuevo Mundo
## 66 grayi 27.044600 3.831300 15.437950 Nuevo Mundo
## 67 nudigenis 14.089200 -6.602100 3.743550 Nuevo Mundo
## 68 sanchezorum 0.005500 -7.216700 -3.605600 Nuevo Mundo
## 69 maculirostris 0.850000 -4.437300 -1.793650 Nuevo Mundo
## 70 jamaicensis 18.082900 18.082900 18.082900 Nuevo Mundo
## 71 assimilis 28.373000 7.609400 17.991200 Nuevo Mundo
## 72 daguae 7.843656 -0.052300 3.895678 Nuevo Mundo
## 73 albicollis 10.713700 -35.250100 -12.268200 Nuevo Mundo
## 74 rufopalliatus 33.932900 17.067000 25.499950 Nuevo Mundo
## 75 rufitorques 16.800000 13.940500 15.370250 Nuevo Mundo
## 76 migratorius 64.862600 16.144500 40.503550 Nuevo Mundo
## 77 swalesi 18.561646 18.242000 18.401823 Nuevo Mundo
## 78 aurantius 18.167872 18.047400 18.107636 Nuevo Mundo
## 79 plumbeus 26.506500 18.157100 22.331800 Nuevo Mundo
## 80 lherminieri 16.310800 15.370900 15.840850 Nuevo Mundo
## 81 eremita -37.086900 -37.423800 -37.255350 Viejo Mundo
dist_lat3 <- function(X, mundo = "ambos") {
# graficar un histograma por especie
res <- lapply(unique(X$Specific_epithet), function(z)
{
sp.dt <- X[X$Specific_epithet == z, ]
lim.Sur <- min(sp.dt$Latitude, na.rm = TRUE)
lim.Norte <- max(sp.dt$Latitude, na.rm = TRUE)
punto.medio <- mean(c(lim.Norte, lim.Sur))
lon <- sp.dt$Longitude[!is.na(sp.dt$Longitude)]
if(all(lon < -25)) mundo <- "Nuevo Mundo"
if(all(lon > -25)) mundo <- "Viejo Mundo"
if(any(lon > -25) & any(lon < -25)) mundo <- "Ambos"
df <- data.frame(especie = z, lim.Norte, lim.Sur, punto.medio, mundo)
})
df <- do.call(rbind, res)
if(mundo == "Viejo") df <- df[ df$mundo =="Viejo Mundo", ] else
if(mundo == "Nuevo") df <- df[df$mundo =="Nuevo Mundo", ] else df <- df
return(df)
}
# hacer lon numerico
turdus$Longitude <- as.numeric(as.character(turdus$Longitude))
dist_lat3(turdus)
## especie lim.Norte lim.Sur punto.medio mundo
## 1 litsitsirupa 14.248900 -29.047600 -7.399350 Viejo Mundo
## 2 flavipes 11.270000 -29.613400 -9.171700 Nuevo Mundo
## 3 leucops 9.604800 -16.250100 -3.322650 Nuevo Mundo
## 4 pelios 13.639600 -12.085226 0.777187 Viejo Mundo
## 5 tephronotus 4.714186 -4.090400 0.311893 Viejo Mundo
## 6 libonyana -6.027000 -31.005100 -18.516050 Viejo Mundo
## 7 olivaceofuscus 0.288500 0.112100 0.200300 Viejo Mundo
## 8 xanthorhynchus 1.551600 1.551600 1.551600 Viejo Mundo
## 9 olivaceus -23.033000 -34.389200 -28.711100 Viejo Mundo
## 10 roehli -4.727300 -5.101200 -4.914250 Viejo Mundo
## 11 abyssinicus 12.028000 -7.880500 2.073750 Viejo Mundo
## 12 smithi -25.767100 -32.287600 -29.027350 Viejo Mundo
## 13 helleri -3.369200 -3.369200 -3.369200 Viejo Mundo
## 14 menachensis 18.965400 18.226400 18.595900 Viejo Mundo
## 15 bewsheri -12.225000 -12.372200 -12.298600 Viejo Mundo
## 16 hortulorum 49.869900 30.206000 40.037950 Viejo Mundo
## 17 unicolor 37.486700 21.583400 29.535050 Viejo Mundo
## 18 dissimilis 26.872000 19.911400 23.391700 Viejo Mundo
## 19 cardis 43.358800 18.758600 31.058700 Viejo Mundo
## 20 albocinctus 30.477600 27.282800 28.880200 Viejo Mundo
## 21 torquatus 69.776300 36.697600 53.236950 Viejo Mundo
## 22 boulboul 34.646060 26.928400 30.787230 Viejo Mundo
## 23 merula 69.585000 -46.895900 11.344550 Ambos
## 24 mandarinus 39.075000 29.307600 34.191300 Viejo Mundo
## 25 maximus 34.646060 29.429000 32.037530 Viejo Mundo
## 26 simillimus 21.114000 6.800000 13.957000 Viejo Mundo
## 27 poliocephalus 24.300000 -18.052000 3.124000 Ambos
## 28 rubrocanus 37.038160 18.588800 27.813480 Viejo Mundo
## 29 kessleri 36.916200 30.896700 33.906450 Viejo Mundo
## 30 feae 40.819500 18.586100 29.702800 Viejo Mundo
## 31 obscurus 63.166100 -1.734200 30.715950 Viejo Mundo
## 32 pallidus 49.438100 25.014500 37.226300 Viejo Mundo
## 33 chrysolaus 46.971000 22.518400 34.744700 Viejo Mundo
## 34 celaenops 34.055300 33.096144 33.575722 Viejo Mundo
## 35 atrogularis 66.686000 27.320168 47.003084 Viejo Mundo
## 36 ruficollis 63.484600 27.757800 45.621200 Viejo Mundo
## 37 naumanni 62.068000 34.688900 48.378450 Viejo Mundo
## 38 eunomus 64.807800 33.230800 49.019300 Viejo Mundo
## 39 pilaris 70.375300 36.028800 53.202050 Viejo Mundo
## 40 iliacus 70.527400 37.397900 53.962650 Ambos
## 41 philomelos 70.124100 -46.897000 11.613550 Ambos
## 42 mupinensis 40.587800 29.850600 35.219200 Viejo Mundo
## 43 viscivorus 68.997300 29.446900 49.222100 Viejo Mundo
## 44 fuscater 11.123700 -16.904000 -2.890150 Nuevo Mundo
## 45 chiguanco -1.733000 -44.800400 -23.266700 Nuevo Mundo
## 46 nigrescens 10.160000 8.803600 9.481800 Nuevo Mundo
## 47 infuscatus 19.661600 13.902900 16.782250 Nuevo Mundo
## 48 serranus 10.417000 -22.188333 -5.885667 Nuevo Mundo
## 49 nigriceps -3.229500 -27.866700 -15.548100 Nuevo Mundo
## 50 subalaris -12.583400 -34.283300 -23.433350 Nuevo Mundo
## 51 reevei -3.650000 -6.301400 -4.975700 Nuevo Mundo
## 52 olivater 11.200000 1.668200 6.434100 Nuevo Mundo
## 53 maranonicus -4.550000 -6.833333 -5.691667 Nuevo Mundo
## 54 fulviventris 8.616400 -5.316700 1.649850 Nuevo Mundo
## 55 rufiventris -4.229800 -38.987900 -21.608850 Nuevo Mundo
## 56 falcklandii -32.466700 -54.844800 -43.655750 Nuevo Mundo
## 57 leucomelas 11.269800 -31.718400 -10.224300 Nuevo Mundo
## 58 amaurochalinus -6.088700 -39.677200 -22.882950 Nuevo Mundo
## 59 plebejus 16.758000 8.497000 12.627500 Nuevo Mundo
## 60 ignobilis 10.303300 -12.866000 -1.281350 Nuevo Mundo
## 61 lawrencii 1.259800 -14.567000 -6.653600 Nuevo Mundo
## 62 fumigatus 10.713700 -16.452500 -2.869400 Nuevo Mundo
## 63 obsoletus 9.644800 -3.898300 2.873250 Nuevo Mundo
## 64 hauxwelli 3.862700 -17.783300 -6.960300 Nuevo Mundo
## 65 haplochrous -14.209000 -14.748900 -14.478950 Nuevo Mundo
## 66 grayi 27.044600 3.831300 15.437950 Nuevo Mundo
## 67 nudigenis 14.089200 -6.602100 3.743550 Nuevo Mundo
## 68 sanchezorum 0.005500 -7.216700 -3.605600 Nuevo Mundo
## 69 maculirostris 0.850000 -4.437300 -1.793650 Nuevo Mundo
## 70 jamaicensis 18.082900 18.082900 18.082900 Nuevo Mundo
## 71 assimilis 28.373000 7.609400 17.991200 Nuevo Mundo
## 72 daguae 7.843656 -0.052300 3.895678 Nuevo Mundo
## 73 albicollis 10.713700 -35.250100 -12.268200 Nuevo Mundo
## 74 rufopalliatus 33.932900 17.067000 25.499950 Nuevo Mundo
## 75 rufitorques 16.800000 13.940500 15.370250 Nuevo Mundo
## 76 migratorius 64.862600 16.144500 40.503550 Nuevo Mundo
## 77 swalesi 18.561646 18.242000 18.401823 Nuevo Mundo
## 78 aurantius 18.167872 18.047400 18.107636 Nuevo Mundo
## 79 plumbeus 26.506500 18.157100 22.331800 Nuevo Mundo
## 80 lherminieri 16.310800 15.370900 15.840850 Nuevo Mundo
## 81 eremita -37.086900 -37.423800 -37.255350 Viejo Mundo
temp_canto <- function(X) {
# graficar un histograma por especie
res <- lapply(unique(X$Specific_epithet), function(z)
{
# sacar datos para una species
sp.dt <- X[X$Specific_epithet == z, ]
# calcular principio y fin y hacerlo una fecha juliana
princ <- min(sp.dt$Date, na.rm = TRUE)
fin <- max(sp.dt$Date, na.rm = TRUE)
# guardar en base de datos
df <- data.frame(especie = z, princ, fin, stringsAsFactors = FALSE)
})
# poner lista de data frame en un solo data frame
df <- do.call(rbind, res)
return(df)
}
# convertir a dia Juliano
turdus$Date <- as.numeric(format(as.Date(turdus$Date, origin = "1900-01-01"), "%j"))
# cantos
cnt <- temp_canto(turdus[grep("song", turdus$Vocalization_type, ignore.case = TRUE), ])
# llamados (usando invert)
llm <- temp_canto(turdus[grep("song", turdus$Vocalization_type, ignore.case = TRUE, invert = TRUE), ])
# remover specie q no tiene cantos
llm <- llm[llm$especie %in% cnt$especie, ]
# remover specie q no tiene llamados
cnt <- cnt[cnt$especie %in% llm$especie, ]
# rango de cantos
rng.cnt <- cnt$fin - cnt$princ
rng.llm <- llm$fin - llm$princ
#poner en base de datos
rng.df <- data.frame(especie = cnt$especie, rng.cnt, rng.llm)
# remover NAs y Infinito
rng.df <- rng.df[complete.cases(rng.df), ]
# tambien puede usar rng.df <- rng.df[!is.na(rng.df$rng.cnt) & !is.na(rng.df$rng.llm), ]
rng.df <- rng.df[!is.infinite(rng.df$rng.cnt), ]
# correr T pareada
t.test(rng.df$rng.cnt, rng.df$rng.llm, paired = TRUE)
##
## Paired t-test
##
## data: rng.df$rng.cnt and rng.df$rng.llm
## t = -2.8369, df = 74, p-value = 0.005874
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -69.13883 -12.08784
## sample estimates:
## mean of the differences
## -40.61333
# calcular rango latitudinal
sp.lat <- dist_lat(turdus)
# usar absoluto de latitud
sp.lat$punto.medio <- abs(sp.lat$punto.medio)
# mezclar bases de datos
sp.rng.alt <- merge(x = sp.lat, y = rng.df, by = "especie")
# correr modelo linear
mod <- lm(formula = rng.cnt ~ punto.medio, data = sp.rng.alt)
# ver resultado
summary(mod)
##
## Call:
## lm(formula = rng.cnt ~ punto.medio, data = sp.rng.alt)
##
## Residuals:
## Min 1Q Median 3Q Max
## -270.19 -118.15 46.79 93.69 226.26
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 280.7588 25.0807 11.194 < 2e-16 ***
## punto.medio -2.8172 0.9667 -2.914 0.00473 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 130.8 on 73 degrees of freedom
## Multiple R-squared: 0.1042, Adjusted R-squared: 0.09193
## F-statistic: 8.492 on 1 and 73 DF, p-value: 0.004733
# graficar
library(ggplot2)
ggplot(sp.rng.alt, aes(x = punto.medio, y = rng.cnt)) +
geom_point() +
labs(x = "Latitud", y = "Temporada de cantos") +
geom_smooth(method = "lm") +
theme_classic()
# correr modelo linear
mod <- lm(formula = rng.llm ~ punto.medio, data = sp.rng.alt)
# ver resultado
summary(mod)
##
## Call:
## lm(formula = rng.llm ~ punto.medio, data = sp.rng.alt)
##
## Residuals:
## Min 1Q Median 3Q Max
## -264.13 -78.67 40.02 81.38 101.68
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 261.4569 20.7201 12.619 <2e-16 ***
## punto.medio 0.0758 0.7987 0.095 0.925
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 108.1 on 73 degrees of freedom
## Multiple R-squared: 0.0001234, Adjusted R-squared: -0.01357
## F-statistic: 0.009007 on 1 and 73 DF, p-value: 0.9247
# graficar
library(ggplot2)
ggplot(sp.rng.alt, aes(x = punto.medio, y = rng.llm)) +
geom_point() +
labs(x = "Latitud", y = "Temporada de llamados") +
geom_smooth(method = "lm") +
theme_classic()